home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gpp-1_42.lha / g++-1.42.0 / cplus-decl.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  282KB  |  8,913 lines

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Process declarations and symbol lookup for C front end.
  23.    Also constructs types; the standard scalar types at initialization,
  24.    and structure, union, array and enum types when they are declared.  */
  25.  
  26. /* ??? not all decl nodes are given the most useful possible
  27.    line numbers.  For example, the CONST_DECLs for enum values.  */
  28.  
  29. #include "config.h"
  30. #include "tree.h"
  31. #include "flags.h"
  32. #include "cplus-tree.h"
  33. #include "cplus-parse.h"
  34. #include <signal.h>
  35. #include "assert.h"
  36. #include "obstack.h"
  37. #include "rtl.h"
  38. #include "insn-flags.h"
  39.  
  40. #define obstack_chunk_alloc xmalloc
  41. #define obstack_chunk_free free
  42.  
  43. extern int xmalloc ();
  44. extern void free ();
  45.  
  46. /* Define this if C structs should have gratuitous typedefing
  47.    done just like C++ structs do.  */
  48. #define BREAK_C_TAGS
  49.  
  50. /* Stack of places to restore the search obstack back to.  */
  51.    
  52. /* Obstack used for remembering local class declarations (like
  53.    enums and static (const) members.  */
  54. #include "stack.h"
  55. static struct obstack decl_obstack;
  56. static struct stack_level *decl_stack;
  57.  
  58. #include "cplus-decl.h"
  59.  
  60. #define NULL 0
  61. #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
  62. #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
  63.  
  64. #ifndef CHAR_TYPE_SIZE
  65. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  66. #endif
  67.  
  68. #ifndef SHORT_TYPE_SIZE
  69. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  70. #endif
  71.  
  72. #ifndef INT_TYPE_SIZE
  73. #define INT_TYPE_SIZE BITS_PER_WORD
  74. #endif
  75.  
  76. #ifndef LONG_TYPE_SIZE
  77. #define LONG_TYPE_SIZE BITS_PER_WORD
  78. #endif
  79.  
  80. #ifndef LONG_LONG_TYPE_SIZE
  81. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  82. #endif
  83.  
  84. #ifndef FLOAT_TYPE_SIZE
  85. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  86. #endif
  87.  
  88. #ifndef DOUBLE_TYPE_SIZE
  89. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  90. #endif
  91.  
  92. #ifndef LONG_DOUBLE_TYPE_SIZE
  93. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  94. #endif
  95.  
  96. static tree grokparms ();
  97. tree grokdeclarator ();
  98. tree pushdecl ();
  99. void push_overloaded_decl ();
  100. void pop_implicit_try_blocks ();
  101.  
  102. #define builtin_function(NAME, TYPE, CODE) \
  103.   define_function (NAME, TYPE, CODE, (void (*)())&pushdecl)
  104. #define auto_function(NAME, TYPE, CODE) \
  105.   define_function (NAME, TYPE, CODE, (void (*)())&push_overloaded_decl)
  106.  
  107. /* static */ void grokclassfn ();
  108. /* static */ tree grokopexpr (), grokoptypename ();
  109.  
  110. static tree lookup_tag ();
  111. static tree lookup_tag_reverse ();
  112. static tree lookup_name_current_level ();
  113. static char *redeclaration_error_message ();
  114. static int parmlist_is_exprlist ();
  115. static int parmlist_is_random ();
  116. static void grok_ctor_properties ();
  117. static void grok_op_properties ();
  118. static void expand_static_init ();
  119. static void deactivate_exception_cleanups ();
  120.  
  121. tree finish_table ();
  122. #ifdef FIELD_XREF
  123. static void FIELD_end_scope();
  124. #endif
  125.  
  126. /* a node which has tree code ERROR_MARK, and whose type is itself.
  127.    All erroneous expressions are replaced with this node.  All functions
  128.    that accept nodes as arguments should avoid generating error messages
  129.    if this node is one of the arguments, since it is undesirable to get
  130.    multiple error messages from one error in the input.  */
  131.  
  132. #undef error_mark_node
  133. tree error_mark_node;
  134. #define error_mark_node (&ERROR_MARK_NODE)
  135.  
  136. /* Erroneous argument lists can use this *IFF* they do not modify it.  */
  137. tree error_mark_list;
  138.  
  139. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  140.  
  141. tree short_integer_type_node;
  142. tree integer_type_node;
  143. tree long_integer_type_node;
  144. tree long_long_integer_type_node;
  145.  
  146. tree short_unsigned_type_node;
  147. tree unsigned_type_node;
  148. tree long_unsigned_type_node;
  149. tree long_long_unsigned_type_node;
  150.  
  151. tree unsigned_char_type_node;
  152. tree signed_char_type_node;
  153. tree char_type_node;
  154.  
  155. tree float_type_node;
  156. tree double_type_node;
  157. tree long_double_type_node;
  158.  
  159. /* a VOID_TYPE node, and the same, packaged in a TREE_LIST.  */
  160.  
  161. tree void_type_node, void_list_node;
  162.  
  163. /* A node for type `void *'.  */
  164.  
  165. tree ptr_type_node;
  166.  
  167. /* A node for type `char *'.  */
  168.  
  169. tree string_type_node;
  170.  
  171. /* Type `char[256]' or something like it.
  172.    Used when an array of char is needed and the size is irrelevant.  */
  173.  
  174. tree char_array_type_node;
  175.  
  176. /* Type `int[256]' or something like it.
  177.    Used when an array of int needed and the size is irrelevant.  */
  178.  
  179. tree int_array_type_node;
  180.  
  181. /* type `int ()' -- used for implicit declaration of functions.  */
  182.  
  183. tree default_function_type;
  184.  
  185. /* function types `double (double)' and `double (double, double)', etc.  */
  186.  
  187. tree double_ftype_double, double_ftype_double_double;
  188. tree int_ftype_int, long_ftype_long;
  189.  
  190. /* Function type `void (void *, void *, int)' and similar ones.  */
  191.  
  192. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  193.  
  194. /* C++ extensions */
  195. tree vtable_entry_type;
  196. tree class_type_node, record_type_node, union_type_node, enum_type_node;
  197. tree exception_type_node, unknown_type_node;
  198.  
  199. /* Function type `void * (long)', 'void (void *)' */
  200. tree ptr_ftype_long, void_ftype_ptr;
  201. tree ptr_ftype_ptr_int_int_ptr, void_ftype_ptr_int_int_ptr_int_int;
  202.  
  203. /* Used for virtual function tables.  */
  204. tree vtbl_mask;
  205.  
  206. /* Array type `(void *)[]' */
  207. tree vtbl_type_node;
  208.  
  209. #ifdef SOS
  210. /* SOS extensions.  */
  211. tree zlink_type, zret_type;
  212. tree zlink, zret;
  213. #endif
  214.  
  215. /* Static decls which do not have static initializers have no
  216.    initializers as far as GNU C is concerned.  EMPTY_INIT_NODE
  217.    is a static initializer which makes varasm code place the decl
  218.    in data rather than in bss space.  Such gymnastics are necessary
  219.    to avoid the problem that the linker will not include a library
  220.    file if all the library appears to contribute are bss variables.  */
  221.  
  222. tree empty_init_node;
  223.  
  224. /* In a destructor, the point at which all derived class destroying
  225.    has been done, just before any base class destroying will be done.  */
  226.  
  227. tree dtor_label;
  228.  
  229. /* In a constructor, the point at which we are ready to return
  230.    the pointer to the initialized object.  */
  231.  
  232. tree ctor_label;
  233.  
  234. /* A FUNCTION_DECL which can call `unhandled_exception'.
  235.    Not neccessarily the one that the user will declare,
  236.    but sufficient to be called by routines that want to abort the program.  */
  237.  
  238. tree unhandled_exception_fndecl;
  239.  
  240. /* A FUNCTION_DECL which can call `abort'.  Not neccessarily the
  241.    one that the user will declare, but sufficient to be called
  242.    by routines that want to abort the program.  */
  243.  
  244. tree abort_fndecl;
  245.  
  246. /* -- end of C++ */
  247.  
  248. /* Two expressions that are constants with value zero.
  249.    The first is of type `int', the second of type `void *'.  */
  250.  
  251. tree integer_zero_node;
  252. tree null_pointer_node;
  253.  
  254. /* A node for the integer constants 1, 2, and 3.  */
  255.  
  256. tree integer_one_node, integer_two_node, integer_three_node;
  257.  
  258. /* An identifier whose name is <value>.  This is used as the "name"
  259.    of the RESULT_DECLs for values of functions.  */
  260.  
  261. tree value_identifier;
  262.  
  263. /* If original DECL_RESULT of current function was a register,
  264.    but due to being an addressable named return value, would up
  265.    on the stack, this variable holds the named return value's
  266.    original location.  */
  267. struct rtx_def *original_result_rtx;
  268.  
  269. /* Sequence of insns which represents base initialization.  */
  270. struct rtx_def *base_init_insns;
  271.  
  272. /* C++: Keep these around to reduce calls to `get_identifier'.
  273.    Identifiers for `this' in member functions and the auto-delete
  274.    parameter for destructors.  */
  275. tree this_identifier, in_charge_identifier;
  276.  
  277. /* While defining an enum type, this is 1 plus the last enumerator
  278.    constant value.  */
  279.  
  280. static tree enum_next_value;
  281.  
  282. /* Parsing a function declarator leaves a list of parameter names
  283.    or a chain or parameter decls here.  */
  284.  
  285. tree last_function_parms;
  286.  
  287. /* Parsing a function declarator leaves here a chain of structure
  288.    and enum types declared in the parmlist.  */
  289.  
  290. static tree last_function_parm_tags;
  291.  
  292. /* After parsing the declarator that starts a function definition,
  293.    `start_function' puts here the list of parameter names or chain of decls.
  294.    `store_parm_decls' finds it here.  */
  295.  
  296. static tree current_function_parms;
  297.  
  298. /* Similar, for last_function_parm_tags.  */
  299. static tree current_function_parm_tags;
  300.  
  301. /* A list (chain of TREE_LIST nodes) of all LABEL_STMTs in the function
  302.    that have names.  Here so we can clear out their names' definitions
  303.    at the end of the function.  */
  304.  
  305. static tree named_labels;
  306.  
  307. /* A list (chain of TREE_LIST nodes) of named label uses.
  308.    The TREE_PURPOSE field is the list of variables defined
  309.    the the label's scope defined at the point of use.
  310.    The TREE_VALUE field is the LABEL_DECL used.
  311.    The TREE_TYPE field holds `current_binding_level' at the
  312.    point of the label's use.
  313.  
  314.    Used only for jumps to as-yet undefined labels, since
  315.    jumps to defined labels can have their validity checked
  316.    by stmt.c.  */
  317.  
  318. static tree named_label_uses;
  319.  
  320. /* A list of objects which have constructors or destructors
  321.    which reside in the global scope.  The decl is stored in
  322.    the TREE_VALUE slot and the initializer is stored
  323.    in the TREE_PURPOSE slot.  */
  324. tree static_aggregates;
  325.  
  326. /* A list of functions which were declared inline, but later had their
  327.    address taken.  Used only for non-virtual member functions, since we can
  328.    find other functions easily enough.  */
  329. tree pending_addressable_inlines;
  330.  
  331. /* A list of overloaded functions which we should forget ever
  332.    existed, such as functions declared in a function's scope,
  333.    once we leave that function's scope.  */
  334. static tree overloads_to_forget;
  335.  
  336. /* The FUNCTION_DECL for the function currently being compiled,
  337.    or 0 if between functions.  */
  338. tree current_function_decl;
  339.  
  340. /* Set to 0 at beginning of a function definition, set to 1 if
  341.    a return statement that specifies a return value is seen.  */
  342.  
  343. int current_function_returns_value;
  344.  
  345. /* Set to 0 at beginning of a function definition, set to 1 if
  346.    a return statement with no argument is seen.  */
  347.  
  348. int current_function_returns_null;
  349.  
  350. /* Set to nonzero by `grokdeclarator' for a function
  351.    whose return type is defaulted, if warnings for this are desired.  */
  352.  
  353. static int warn_about_return_type;
  354.  
  355. /* Nonzero when starting a function delcared `extern inline'.  */
  356.  
  357. static int current_extern_inline;
  358.  
  359. char *language_string = "GNU C++";
  360.  
  361. /* Set to 0 at beginning of a constructor, set to 1
  362.    if that function does an allocation before referencing its
  363.    instance variable.  */
  364. int current_function_assigns_this;
  365. int current_function_just_assigned_this;
  366.  
  367. /* Set to 0 at beginning of a function.  Set non-zero when
  368.    store_parm_decls is called.  Don't call store_parm_decls
  369.    if this flag is non-zero!  */
  370. int current_function_parms_stored;
  371.  
  372. /* Allocate a level of searching.  */
  373. struct stack_level *
  374. push_decl_level (stack, obstack)
  375.      struct stack_level *stack;
  376.      struct obstack *obstack;
  377. {
  378.   struct stack_level tem;
  379.   tem.prev = stack;
  380.  
  381.   return push_stack_level (obstack, &tem, sizeof (tem));
  382. }
  383.  
  384. /* Discard a level of decl allocation.  */
  385.  
  386. static struct stack_level *
  387. pop_decl_level (stack)
  388.      struct stack_level *stack;
  389. {
  390.   tree *bp, *tp;
  391.   struct obstack *obstack = stack->obstack;
  392.   bp = stack->first;
  393.   tp = (tree *)obstack_next_free (obstack);
  394.   while (tp != bp)
  395.     {
  396.       --tp;
  397.       IDENTIFIER_CLASS_VALUE (DECL_NAME (*tp)) = NULL_TREE;
  398.     }
  399.   return pop_stack_level (stack);
  400. }
  401.  
  402. /* For each binding contour we allocate a binding_level structure
  403.  * which records the names defined in that contour.
  404.  * Contours include:
  405.  *  0) the global one
  406.  *  1) one for each function definition,
  407.  *     where internal declarations of the parameters appear.
  408.  *  2) one for each compound statement,
  409.  *     to record its declarations.
  410.  *
  411.  * The current meaning of a name can be found by searching the levels from
  412.  * the current one out to the global one.
  413.  *
  414.  * Off to the side, may be the class_binding_level.  This exists
  415.  * only to catch class-local declarations.  It is otherwise
  416.  * nonexistent.
  417.  * 
  418.  * Also there may be binding levels that catch cleanups that
  419.  * must be run when exceptions occur.
  420.  */
  421.  
  422. /* Note that the information in the `names' component of the global contour
  423.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  424.  
  425. struct binding_level
  426.   {
  427.     /* A chain of _DECL nodes for all variables, constants, functions,
  428.      * and typedef types.  These are in the reverse of the order supplied.
  429.      */
  430.     tree names;
  431.  
  432.     /* A list of structure, union and enum definitions,
  433.      * for looking up tag names.
  434.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  435.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  436.      * or ENUMERAL_TYPE node.
  437.      *
  438.      * C++: the TREE_VALUE nodes can be simple types for component_bindings.
  439.      *
  440.      */
  441.     tree tags;
  442.  
  443.     /* For each level, a list of shadowed outer-level local definitions
  444.        to be restored when this level is popped.
  445.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  446.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  447.     tree shadowed;
  448.  
  449.     /* Same, for IDENTIFIER_CLASS_VALUE.  */
  450.     tree class_shadowed;
  451.  
  452.     /* For each level (except not the global one),
  453.        a chain of LET_STMT nodes for all the levels
  454.        that were entered and exited one level down.  */
  455.     tree blocks;
  456.  
  457.     /* The binding level which this one is contained in (inherits from).  */
  458.     struct binding_level *level_chain;
  459.  
  460.     /* Number of decls in `names' that have incomplete 
  461.        structure or union types.  */
  462.     unsigned short n_incomplete;
  463.  
  464.     /* 1 for the level that holds the parameters of a function.
  465.        2 for the level that holds a class declaration.
  466.        3 for levels that hold parameter declarations.  */
  467.     unsigned parm_flag : 4;
  468.  
  469.     /* 1 means make a LET_STMT for this level regardless of all else.
  470.        2 for temporary binding contours created by the compiler.  */
  471.     unsigned keep : 3;
  472.  
  473.     /* Nonzero if this level "doesn't exist" for tags.  */
  474.     unsigned tag_transparent : 1;
  475.  
  476.     /* Nonzero if this level can safely have additional
  477.        cleanup-needing variables added to it.  */
  478.     unsigned more_cleanups_ok : 1;
  479.     unsigned have_cleanups : 1;
  480.  
  481.     /* Nonzero if this level can safely have additional
  482.        exception-raising statements added to it.  */
  483.     unsigned more_exceptions_ok : 1;
  484.     unsigned have_exceptions : 1;
  485.  
  486.     /* Four bits left for this word.  */
  487.   };
  488.  
  489. #define NULL_BINDING_LEVEL (struct binding_level *) NULL
  490.   
  491. /* The binding level currently in effect.  */
  492.  
  493. static struct binding_level *current_binding_level;
  494.  
  495. /* The binding level of the current class, if any.  */
  496.  
  497. static struct binding_level *class_binding_level;
  498.  
  499. /* A chain of binding_level structures awaiting reuse.  */
  500.  
  501. static struct binding_level *free_binding_level;
  502.  
  503. /* The outermost binding level, for names of file scope.
  504.    This is created when the compiler is started and exists
  505.    through the entire run.  */
  506.  
  507. static struct binding_level *global_binding_level;
  508.  
  509. /* Binding level structures are initialized by copying this one.  */
  510.  
  511. static struct binding_level clear_binding_level;
  512.  
  513. /* Nonzero means unconditionally make a LET_STMT for the next level pushed.  */
  514.  
  515. static int keep_next_level_flag;
  516.  
  517. #define PUSH_BINDING_LEVEL(NEWLEVEL, TAG_TRANSPARENT, KEEP) \
  518. do {                                    \
  519.   /* Add this level to the front of the chain (stack) of levels that    \
  520.      are active.  */                            \
  521.   *NEWLEVEL = clear_binding_level;                    \
  522.   if (class_binding_level)                        \
  523.     {                                    \
  524.       NEWLEVEL->level_chain = class_binding_level;            \
  525.       class_binding_level = 0;                        \
  526.     }                                    \
  527.   else                                    \
  528.     {                                    \
  529.       NEWLEVEL->level_chain = current_binding_level;            \
  530.     }                                    \
  531.   current_binding_level = NEWLEVEL;                    \
  532.   NEWLEVEL->tag_transparent = TAG_TRANSPARENT;                \
  533.   NEWLEVEL->more_cleanups_ok = 1;                    \
  534.   NEWLEVEL->more_exceptions_ok = 1;                    \
  535.   NEWLEVEL->keep = KEEP;                        \
  536. } while (0)
  537.  
  538. #define POP_BINDING_LEVEL \
  539. do {                                    \
  540.   /* Pop the current level, and free the structure for reuse.  */    \
  541.   {                                    \
  542.     register struct binding_level *level = current_binding_level;    \
  543.     current_binding_level = current_binding_level->level_chain;        \
  544.     level->level_chain = free_binding_level;                \
  545.     free_binding_level = level;                        \
  546.     if (current_binding_level->parm_flag == 2)                \
  547.       {                                    \
  548.     class_binding_level = current_binding_level;            \
  549.     do                                \
  550.       {                                \
  551.         current_binding_level = current_binding_level->level_chain;    \
  552.       }                                \
  553.     while (current_binding_level->parm_flag == 2);            \
  554.       }                                    \
  555.   }                                    \
  556. } while (0)
  557.  
  558. /* Create a new `struct binding_level'.  */
  559.  
  560. static
  561. struct binding_level *
  562. make_binding_level ()
  563. {
  564.   /* NOSTRICT */
  565.   return (struct binding_level *) xmalloc (sizeof (struct binding_level));
  566. }
  567.  
  568. /* Nonzero if we are currently in the global binding level.  */
  569.  
  570. int
  571. global_bindings_p ()
  572. {
  573.   return current_binding_level == global_binding_level;
  574. }
  575.  
  576. void
  577. keep_next_level ()
  578. {
  579.   keep_next_level_flag = 1;
  580. }
  581.  
  582. /* Identify this binding level as a level of parameters.  */
  583.  
  584. void
  585. declare_parm_level ()
  586. {
  587.   current_binding_level->parm_flag = 1;
  588. }
  589.  
  590. /* Identify this binding level as a level of a default exception handler.  */
  591.  
  592. void
  593. declare_implicit_exception ()
  594. {
  595.   current_binding_level->parm_flag = 3;
  596. }
  597.  
  598. /* Nonzero if current binding contour contains expressions
  599.    that might raise exceptions.  */
  600.  
  601. int
  602. have_exceptions_p ()
  603. {
  604.   return current_binding_level->have_exceptions;
  605. }
  606.  
  607. /* Enter a new binding level.
  608.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  609.    not for that of tags.  */
  610.  
  611. void
  612. pushlevel (tag_transparent)
  613.      int tag_transparent;
  614. {
  615.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  616.  
  617.   /* If this is the top level of a function,
  618.      just make sure that NAMED_LABELS is 0.
  619.      They should have been set to 0 at the end of the previous function.  */
  620.  
  621.   if (current_binding_level == global_binding_level)
  622.     assert (named_labels == NULL_TREE);
  623.  
  624.   /* Reuse or create a struct for this binding level.  */
  625.  
  626.   if (free_binding_level)
  627.     {
  628.       newlevel = free_binding_level;
  629.       free_binding_level = free_binding_level->level_chain;
  630.     }
  631.   else
  632.     {
  633.       newlevel = make_binding_level ();
  634.     }
  635.   PUSH_BINDING_LEVEL (newlevel, tag_transparent, keep_next_level_flag);
  636. #ifdef FIELD_XREF
  637.   FIELD_xref_start_scope(newlevel);
  638. #endif
  639.   keep_next_level_flag = 0;
  640. }
  641.  
  642. void
  643. pushlevel_temporary (tag_transparent)
  644.      int tag_transparent;
  645. {
  646.   pushlevel (tag_transparent);
  647.   current_binding_level->keep = 2;
  648.   clear_last_expr ();
  649. #if 0
  650.   /* Don't call push_momentary here!  It will cause cleanups
  651.      to be allocated on the momentary obstack, and they
  652.      will be overwritten by the next statement.  */
  653.   push_momentary ();
  654. #endif
  655.   expand_start_bindings (0);
  656. }
  657.  
  658. /* Exit a binding level.
  659.    Pop the level off, and restore the state of the identifier-decl mappings
  660.    that were in effect when this level was entered.
  661.  
  662.    If KEEP == 1, this level had explicit declarations, so
  663.    and create a "block" (a LET_STMT node) for the level
  664.    to record its declarations and subblocks for symbol table output.
  665.  
  666.    If KEEP == 2, this level's subblocks go to the front,
  667.    not the back of the current binding level.  This happens,
  668.    for instance, when code for constructors and destructors
  669.    need to generate code at the end of a function which must
  670.    be moved up to the front of the function.
  671.  
  672.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  673.    so create a block as if KEEP were set and also clear out all
  674.    label names.
  675.  
  676.    If REVERSE is nonzero, reverse the order of decls before putting
  677.    them into the LET_STMT.  */
  678.  
  679. tree
  680. poplevel (keep, reverse, functionbody)
  681.      int keep;
  682.      int reverse;
  683.      int functionbody;
  684. {
  685.   register tree link;
  686.   /* The chain of decls was accumulated in reverse order.
  687.      Put it into forward order, just for cleanliness.  */
  688.   tree decls;
  689.   int tmp = functionbody;
  690.   int implicit_try_block = current_binding_level->parm_flag == 3;
  691.   int real_functionbody = current_binding_level->keep == 2
  692.     ? ((functionbody = 0), tmp) : functionbody;
  693.   tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
  694.   tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  695.   tree block = 0;
  696.  
  697. #ifdef FIELD_XREF
  698.   FIELD_xref_end_scope(current_binding_level,
  699.                current_binding_level->level_chain,
  700.                current_binding_level->parm_flag,
  701.                current_binding_level->keep,
  702.                current_binding_level->tag_transparent);
  703. #endif
  704.  
  705.   if (current_binding_level->keep == 1)
  706.     keep = 1;
  707.  
  708.   /* This warning is turned off because it causes warnings for
  709.      declarations like `extern struct foo *x'.  */
  710. #if 0
  711.   /* Warn about incomplete structure types in this level.  */
  712.   for (link = tags; link; link = TREE_CHAIN (link))
  713.     if (TYPE_SIZE (TREE_VALUE (link)) == 0)
  714.       {
  715.     tree type = TREE_VALUE (link);
  716.     char *errmsg;
  717.     switch (TREE_CODE (type))
  718.       {
  719.       case RECORD_TYPE:
  720.         errmsg = "`struct %s' incomplete in scope ending here";
  721.         break;
  722.       case UNION_TYPE:
  723.         errmsg = "`union %s' incomplete in scope ending here";
  724.         break;
  725.       case ENUMERAL_TYPE:
  726.         errmsg = "`enum %s' incomplete in scope ending here";
  727.         break;
  728.       }
  729.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  730.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  731.     else
  732.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  733.       error (errmsg, TYPE_NAME_STRING (type));
  734.       }
  735. #endif /* 0 */
  736.  
  737.   /* Get the decls in the order they were written.
  738.      Usually current_binding_level->names is in reverse order.
  739.      But parameter decls were previously put in forward order.  */
  740.  
  741.   if (reverse)
  742.     current_binding_level->names
  743.       = decls = nreverse (current_binding_level->names);
  744.   else
  745.     decls = current_binding_level->names;
  746.  
  747.   /* If there were any declarations or structure tags in that level,
  748.      or if this level is a function body,
  749.      create a LET_STMT to record them for the life of this function.  */
  750.  
  751.   if (keep == 1 || functionbody > 0)
  752.     block = build_let (0, 0, keep ? decls : 0,
  753.                subblocks, 0, keep ? tags : 0);
  754.  
  755.   /* In each subblock, record that this is its superior.  */
  756.  
  757.   if (keep >= 0)
  758.     for (link = subblocks; link; link = TREE_CHAIN (link))
  759.       STMT_SUPERCONTEXT (link) = block;
  760.  
  761.   /* Clear out the meanings of the local variables of this level;
  762.      also record in each decl which block it belongs to.  */
  763.  
  764.   for (link = decls; link; link = TREE_CHAIN (link))
  765.     {
  766.       if (DECL_NAME (link) != 0)
  767.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  768.       DECL_CONTEXT (link) = block;
  769.     }
  770.  
  771.   /* Restore all name-meanings of the outer levels
  772.      that were shadowed by this level.  */
  773.  
  774.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  775.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  776.   for (link = current_binding_level->class_shadowed;
  777.        link;
  778.        link = TREE_CHAIN (link))
  779.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  780.  
  781.   /* If the level being exited is the top level of a function,
  782.      check over all the labels.  */
  783.  
  784.   if (functionbody)
  785.     {
  786.       /* Clear out the definitions of all label names,
  787.      since their scopes end here.  */
  788.  
  789.       for (link = named_labels; link; link = TREE_CHAIN (link))
  790.     {
  791.       if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
  792.         {
  793.           error ("label `%s' used somewhere above but not defined",
  794.              IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (link))));
  795.           /* Avoid crashing later.  */
  796.           define_label (input_filename, 1, DECL_NAME (TREE_VALUE (link)));
  797.         }
  798.       else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
  799.         warning_with_decl (TREE_VALUE (link), 
  800.                    "label `%s' defined but not used");
  801.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), 0);
  802.     }
  803.  
  804.       named_labels = 0;
  805.     }
  806.  
  807.   /* Any uses of undefined labels now operate under constraints
  808.      of next binding contour.  */
  809.   {
  810.     struct binding_level *level_chain;
  811.     level_chain = current_binding_level->level_chain;
  812.     if (level_chain)
  813.       {
  814.     tree labels;
  815.     for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
  816.       if (TREE_TYPE (labels) == (tree)current_binding_level)
  817.         {
  818.           TREE_TYPE (labels) = (tree)level_chain;
  819.           TREE_PURPOSE (labels) = level_chain->names;
  820.         }
  821.       }
  822.   }
  823.  
  824.   tmp = current_binding_level->keep;
  825.  
  826.   POP_BINDING_LEVEL;
  827.   if (functionbody > 0)
  828.     {
  829.       DECL_INITIAL (current_function_decl) = block;
  830.       /* If this is the top level block of a function,
  831.      the vars are the function's parameters.
  832.      Don't leave them in the LET_STMT because they are
  833.      found in the FUNCTION_DECL instead.  */
  834.       STMT_VARS (block) = 0;
  835.     }
  836.   else if (block)
  837.     current_binding_level->blocks
  838.       = chainon (current_binding_level->blocks, block);
  839.   /* If we did not make a block for the level just exited,
  840.      any blocks made for inner levels
  841.      (since they cannot be recorded as subblocks in that level)
  842.      must be carried forward so they will later become subblocks
  843.      of something else.  */
  844.   else if (subblocks)
  845.     if (keep == 2)
  846.       current_binding_level->blocks = chainon (subblocks, current_binding_level->blocks);
  847.     else
  848.       current_binding_level->blocks
  849.         = chainon (current_binding_level->blocks, subblocks);
  850.  
  851.   /* Take care of compiler's internal binding structures.  */
  852.   if (tmp == 2 && !implicit_try_block)
  853.     {
  854. #if 0
  855.       /* We did not call push_momentary for this
  856.      binding contour, so there is nothing to pop.  */
  857.       pop_momentary ();
  858. #endif
  859.       expand_end_bindings (getdecls (), keep, 1);
  860.       block = poplevel (keep, reverse, real_functionbody);
  861.     }
  862.   if (block)
  863.     TREE_USED (block) = 1;
  864.   return block;
  865. }
  866.  
  867. /* Add BLOCK to the current list of blocks for this binding contour.  */
  868. void
  869. add_block_current_level (block)
  870.      tree block;
  871. {
  872.   current_binding_level->blocks
  873.     = chainon (current_binding_level->blocks, block);
  874. }
  875.  
  876. /* Do a pushlevel for class declarations.  */
  877. void
  878. pushlevel_class ()
  879. {
  880.   pushlevel (0);
  881.   decl_stack = push_decl_level (decl_stack, &decl_obstack);
  882.   class_binding_level = current_binding_level;
  883.   class_binding_level->parm_flag = 2;
  884.   do
  885.     {
  886.       current_binding_level = current_binding_level->level_chain;
  887.     }
  888.   while (current_binding_level->parm_flag == 2);
  889. }
  890.  
  891. /* ...and a poplevel for class declarations.  */
  892. tree
  893. poplevel_class ()
  894. {
  895.   register struct binding_level *level = class_binding_level;
  896.   tree block = 0;
  897.   tree shadowed;
  898.  
  899.   if (level == 0)
  900.     {
  901.       while (current_binding_level && class_binding_level == 0)
  902.     block = poplevel (0, 0, 0);
  903.       if (current_binding_level == 0)
  904.     fatal ("syntax error too serious");
  905.       level = class_binding_level;
  906.     }
  907.   decl_stack = pop_decl_level (decl_stack);
  908.   for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  909.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  910.  
  911. #ifdef FIELD_XREF
  912.   FIELD_xref_end_scope(class_binding_level,
  913.                class_binding_level->level_chain,
  914.                class_binding_level->parm_flag,
  915.                class_binding_level->keep,
  916.                class_binding_level->tag_transparent);
  917. #endif
  918.  
  919.   class_binding_level = level->level_chain;
  920.  
  921.   level->level_chain = free_binding_level;
  922.   free_binding_level = level;
  923.   if (class_binding_level->parm_flag != 2)
  924.     class_binding_level = 0;
  925.   return block;
  926. }
  927.  
  928. /* Push a definition of struct, union or enum tag "name".
  929.    "type" should be the type node.
  930.    We assume that the tag "name" is not already defined.
  931.  
  932.    Note that the definition may really be just a forward reference.
  933.    In that case, the TYPE_SIZE will be zero.
  934.  
  935.    C++ gratuitously puts all these tags in the name space. */
  936.  
  937. void
  938. pushtag (name, type)
  939.      tree name, type;
  940. {
  941.   register struct binding_level *b;
  942.  
  943.   if (class_binding_level)
  944.     b = class_binding_level;
  945.   else
  946.     {
  947.       b = current_binding_level;
  948.       while (b->tag_transparent) b = b->level_chain;
  949.     }
  950.  
  951.   if (name)
  952.     {
  953.       /* Record the identifier as the type's name if it has none.  */
  954.  
  955.       if (TYPE_NAME (type) == 0)
  956.         TYPE_NAME (type) = name;
  957.  
  958.       if (b == global_binding_level)
  959.     b->tags = perm_tree_cons (name, type, b->tags);
  960.       else
  961.     b->tags = saveable_tree_cons (name, type, b->tags);
  962.  
  963.       /* Do C++ gratuitous typedefing.  Note that we put the
  964.          TYPE_DECL in the TREE_TYPE of the IDENTIFIER_NODE.  */
  965.       if (TREE_TYPE (name) != TYPE_NAME (type)
  966. #ifndef BREAK_C_TAGS
  967.       /* This *should* only happen in C++ language scope.
  968.          But everybody else seems to think otherwise.  */
  969.       && current_lang_name == lang_name_cplusplus
  970. #endif
  971.       && (TREE_CODE (type) != RECORD_TYPE
  972.           || class_binding_level == 0
  973.           || !CLASSTYPE_DECLARED_EXCEPTION (type)))
  974.         {
  975.           register tree t = build_decl (TYPE_DECL, name, type);
  976.       if (!TREE_NONLOCAL (type))
  977.         t = pushdecl (t);
  978.           TYPE_NAME (type) = t;
  979.           TREE_TYPE (name) = t;
  980.         }
  981.       if (b->parm_flag == 2)
  982.     {
  983.       TREE_NONLOCAL (type) = 1;
  984.       IDENTIFIER_CLASS_VALUE (name) = TYPE_NAME (type);
  985.       CLASSTYPE_TAGS (current_class_type) = b->tags;
  986.     }
  987.     }
  988. }
  989.  
  990. /* Subroutine of duplicate_decls: return truthvalue of whether
  991.    or not types of these decls match.  */
  992. static int
  993. decls_match (newdecl, olddecl)
  994.      tree newdecl, olddecl;
  995. {
  996.   int types_match;
  997.  
  998.   if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL)
  999.     {
  1000.       tree f1 = TREE_TYPE (newdecl);
  1001.       tree f2 = TREE_TYPE (olddecl);
  1002.       tree p1 = TYPE_ARG_TYPES (f1);
  1003.       tree p2 = TYPE_ARG_TYPES (f2);
  1004.  
  1005.       /* When we parse a static member function definition,
  1006.      we put together a FUNCTION_DECL which thinks its type
  1007.      is METHOD_TYPE.  Change that to FUNCTION_TYPE, and
  1008.      proceed.  */
  1009.       if (TREE_CODE (f1) == METHOD_TYPE
  1010.       && DECL_STATIC_FUNCTION_P (olddecl))
  1011.     {
  1012.       tree n1;
  1013.       p1 = TREE_CHAIN (p1);
  1014.       n1 = build_function_type (TREE_TYPE (f1), p1);
  1015.       n1 = build_type_variant (n1, TREE_READONLY (f1), TREE_VOLATILE (f1));
  1016.       n1 = build_exception_variant (TYPE_METHOD_BASETYPE (f1), n1, TYPE_RAISES_EXCEPTIONS (f1));
  1017.       TREE_TYPE (newdecl) = n1;
  1018.       f1 = n1;
  1019.       DECL_STATIC_FUNCTION_P (newdecl) = 1;
  1020.     }
  1021.       /* Here we must take care of the case where new default
  1022.      parameters are specified.  Also, warn if an old
  1023.      declaration becomes ambiguous because default
  1024.      parameters may cause the two to be ambiguous.  */
  1025.       if (TREE_CODE (f1) != TREE_CODE (f2))
  1026.     {
  1027.       if (TREE_CODE (f1) == OFFSET_TYPE)
  1028.         compiler_error_with_decl (newdecl, "`%s' redeclared as member function");
  1029.       else
  1030.         compiler_error_with_decl (newdecl, "`%s' redeclared as non-member function");
  1031.       return 0;
  1032.     }
  1033.  
  1034.       if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)),
  1035.              TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 1))
  1036.     {
  1037.       types_match = compparms (p1, p2, 1);
  1038. #ifndef MERGED
  1039.       /* C++: copy friendlist *before* we get smooshed.  */
  1040.       if (DECL_FRIENDLIST (olddecl) && !DECL_FRIENDLIST (newdecl))
  1041.         DECL_FRIENDLIST (newdecl) = DECL_FRIENDLIST (olddecl);
  1042. #endif
  1043.     }
  1044.       else types_match = 0;
  1045.     }
  1046.   else
  1047.     {
  1048.       if (TREE_TYPE (newdecl) == error_mark_node)
  1049.     types_match = TREE_TYPE (olddecl) == error_mark_node;
  1050.       else
  1051.     types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
  1052.     }
  1053.  
  1054.   return types_match;
  1055. }
  1056.  
  1057. /* Handle when a new declaration NEWDECL has the same name as an old
  1058.    one OLDDECL in the same binding contour.  Prints an error message
  1059.    if appropriate.
  1060.  
  1061.    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
  1062.    Otherwise, return 0.  */
  1063.  
  1064. static int
  1065. duplicate_decls (newdecl, olddecl)
  1066.      register tree newdecl, olddecl;
  1067. {
  1068.   extern struct obstack permanent_obstack;
  1069.   int types_match;
  1070.   int new_is_definition;
  1071.  
  1072.   if (TREE_CODE (olddecl) == TREE_LIST
  1073.       && TREE_CODE (newdecl) == FUNCTION_DECL)
  1074.     {
  1075.       /* If a new decl finds a list of old decls, then
  1076.      we assume that the new decl has C linkage, and
  1077.      that the old decls have C++ linkage.  In this case,
  1078.      we must look through the list to see whether
  1079.      there is an ambiguity or not.  */
  1080.       tree olddecls = olddecl;
  1081.  
  1082.       /* If the overload list is empty, just install the decl.  */
  1083.       if (TREE_VALUE (olddecls) == NULL_TREE)
  1084.     {
  1085.       TREE_VALUE (olddecls) = newdecl;
  1086.       return 1;
  1087.     }
  1088.  
  1089.       while (olddecls)
  1090.     {
  1091.       if (decls_match (newdecl, TREE_VALUE (olddecls)))
  1092.         {
  1093.           if (TREE_CODE (newdecl) == VAR_DECL)
  1094.         ;
  1095.           else if (DECL_LANGUAGE (newdecl)
  1096.                != DECL_LANGUAGE (TREE_VALUE (olddecls)))
  1097.         {
  1098.           error_with_decl (newdecl, "declaration of `%s' with different language linkage");
  1099.           error_with_decl (TREE_VALUE (olddecls), "previous declaration here");
  1100.         }
  1101.           types_match = 1;
  1102.           break;
  1103.         }
  1104.       olddecls = TREE_CHAIN (olddecls);
  1105.     }
  1106.       if (olddecls)
  1107.     olddecl = TREE_VALUE (olddecl);
  1108.       else
  1109.     return 1;
  1110.     }
  1111.   else
  1112.     types_match = decls_match (newdecl, olddecl);
  1113.  
  1114.   if (TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK
  1115.       || TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK)
  1116.     types_match = 0;
  1117.  
  1118.   /* If this decl has linkage, and the old one does too, maybe no error.  */
  1119.   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
  1120.     {
  1121.       error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
  1122.       if (TREE_CODE (olddecl) == TREE_LIST)
  1123.     olddecl = TREE_VALUE (olddecl);
  1124.       error_with_decl (olddecl, "previous declaration of `%s'");
  1125.  
  1126.       /* New decl is completely inconsistent with the old one =>
  1127.      tell caller to replace the old one.  */
  1128.  
  1129.       return 0;
  1130.     }
  1131.  
  1132.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1133.     {
  1134.       /* Now that functions must hold information normally held
  1135.      by field decls, there is extra work to do so that
  1136.      declaration information does not get destroyed during
  1137.      definition.  */
  1138.       if (DECL_VINDEX (olddecl) && ! DECL_VINDEX (newdecl))
  1139.     DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
  1140.       if (DECL_VCONTEXT (olddecl) && ! DECL_VCONTEXT (newdecl))
  1141.     DECL_VCONTEXT (newdecl) = DECL_VCONTEXT (olddecl);
  1142.       if (DECL_FIELD_CONTEXT (olddecl) && ! DECL_FIELD_CONTEXT (newdecl))
  1143.     DECL_FIELD_CONTEXT (newdecl) = DECL_FIELD_CONTEXT (olddecl);
  1144. #ifdef SOS
  1145.       if (DECL_DINDEX (olddecl) && ! DECL_DINDEX (newdecl))
  1146.     DECL_DINDEX (newdecl) = DECL_DINDEX (newdecl);
  1147. #endif
  1148.       if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
  1149.     DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
  1150.     }
  1151.  
  1152.   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
  1153.       && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl)
  1154.     /* If -traditional, avoid error for redeclaring fcn
  1155.        after implicit decl.  */
  1156.     ;
  1157.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1158.        && DECL_FUNCTION_CODE (olddecl) != NOT_BUILT_IN)
  1159.     {
  1160.       if (!types_match)
  1161.     error_with_decl (newdecl, "conflicting types for built-in function `%s'");
  1162.       else if (extra_warnings)
  1163.     warning_with_decl (newdecl, "built-in function `%s' redeclared");
  1164.     }
  1165.   else if (!types_match)
  1166.     {
  1167.       tree oldtype = TREE_TYPE (olddecl);
  1168.       tree newtype = TREE_TYPE (newdecl);
  1169.       int give_error = 0;
  1170.  
  1171.       /* Already complained about this, so don't do so again.  */
  1172.       if (current_class_type == NULL_TREE
  1173.       || IDENTIFIER_ERROR_LOCUS (DECL_NAME (newdecl)) != current_class_type)
  1174.     {
  1175.       give_error = 1;
  1176.       error_with_decl (newdecl, "conflicting types for `%s'");
  1177.     }
  1178.  
  1179.       /* Check for function type mismatch
  1180.      involving an empty arglist vs a nonempty one.  */
  1181.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  1182.       && comptypes (TREE_TYPE (oldtype),
  1183.             TREE_TYPE (newtype), 1)
  1184.       && ((TYPE_ARG_TYPES (oldtype) == 0
  1185.            && DECL_INITIAL (olddecl) == 0)
  1186.           || (TYPE_ARG_TYPES (newtype) == 0
  1187.           && DECL_INITIAL (newdecl) == 0)))
  1188.     {
  1189.       /* Classify the problem further.  */
  1190.       register tree t = TYPE_ARG_TYPES (oldtype);
  1191.       if (t == 0)
  1192.         t = TYPE_ARG_TYPES (newtype);
  1193.       for (; t; t = TREE_CHAIN (t))
  1194.         {
  1195.           register tree type = TREE_VALUE (t);
  1196.  
  1197.           if (TREE_CHAIN (t) == 0 && type != void_type_node)
  1198.         {
  1199.           error ("A parameter list with an ellipsis can't match");
  1200.           error ("an empty parameter name list declaration.");
  1201.           break;
  1202.         }
  1203.  
  1204.           if (type == float_type_node
  1205.           || (TREE_CODE (type) == INTEGER_TYPE
  1206.               && (TYPE_PRECISION (type)
  1207.               < TYPE_PRECISION (integer_type_node))))
  1208.         {
  1209.           error ("An argument type that has a default promotion");
  1210.           error ("can't match an empty parameter name list declaration.");
  1211.           break;
  1212.         }
  1213.         }
  1214.     }
  1215.       if (give_error)
  1216.     error_with_decl (olddecl, "previous declaration of `%s'");
  1217.  
  1218.       /* There is one thing GNU C++ cannot tolerate: a constructor
  1219.      which takes the type of object being constructed.
  1220.      Farm that case out here.  */
  1221.       if (TREE_CODE (newdecl) == FUNCTION_DECL
  1222.       && DECL_CONSTRUCTOR_P (newdecl))
  1223.     {
  1224.       tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype));
  1225.  
  1226.       if (tmp != NULL_TREE
  1227.           && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp))
  1228.           == TYPE_METHOD_BASETYPE (newtype)))
  1229.         {
  1230.           tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl));
  1231.           tree argtypes
  1232.         = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)),
  1233.                    TREE_CHAIN (tmp));
  1234.  
  1235.           DECL_ARG_TYPE (parm)
  1236.         = TREE_TYPE (parm)
  1237.           = TYPE_REFERENCE_TO (TREE_VALUE (tmp));
  1238.  
  1239.           TREE_TYPE (newdecl) = newtype
  1240.         = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype),
  1241.                        TREE_TYPE (newtype), argtypes);
  1242.           error ("constructor cannot take as argument the type being constructed");
  1243.           SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (newdecl), current_class_type);
  1244.         }
  1245.     }
  1246.     }
  1247.   else
  1248.     {
  1249.       char *errmsg = redeclaration_error_message (newdecl, olddecl);
  1250.       if (errmsg)
  1251.     {
  1252.       error_with_decl (newdecl, errmsg);
  1253.       if (DECL_LANG_SPECIFIC (olddecl)
  1254.           && DECL_COMPILER_GENERATED_P (olddecl))
  1255.         DECL_COMPILER_GENERATED_P (olddecl) = 0;
  1256.       else
  1257.         error_with_decl (olddecl,
  1258.                  "here is the previous declaration of `%s'");
  1259.     }
  1260.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1261.            && DECL_INITIAL (olddecl) != 0
  1262.            && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == 0
  1263.            && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0)
  1264.     {
  1265.       /* Prototype decl follows defn w/o prototype.  */
  1266.       warning_with_decl (newdecl, "prototype for `%s'");
  1267.       warning_with_decl (olddecl,
  1268.                  "follows non-prototype definition here");
  1269.     }
  1270.  
  1271.       /* These bits are logically part of the type.  */
  1272.       if (pedantic
  1273.       && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
  1274.           || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
  1275.     error_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
  1276.     }
  1277.  
  1278.   /* Deal with C++: must preserve virtual function table size.  */
  1279.   if (TREE_CODE (olddecl) == TYPE_DECL)
  1280.     {
  1281.       if (TYPE_LANG_SPECIFIC (TREE_TYPE (newdecl))
  1282.           && TYPE_LANG_SPECIFIC (TREE_TYPE (olddecl)))
  1283.     {
  1284.       CLASSTYPE_VSIZE (TREE_TYPE (newdecl))
  1285.         = CLASSTYPE_VSIZE (TREE_TYPE (olddecl));
  1286.       CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (newdecl))
  1287.         = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (olddecl));
  1288.     }
  1289.     }
  1290.  
  1291.   new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
  1292.                && DECL_INITIAL (newdecl) != 0);
  1293.  
  1294.   /* Copy all the DECL_... slots specified in the new decl
  1295.      except for any that we copy here from the old type.  */
  1296.  
  1297.   if (types_match)
  1298.     {
  1299.       /* Automatically handles default parameters.  */
  1300.       tree oldtype = TREE_TYPE (olddecl);
  1301.       /* Merge the data types specified in the two decls.  */
  1302.       tree newtype = commontype (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
  1303.  
  1304.       if (TREE_CODE (newdecl) == VAR_DECL)
  1305.     DECL_EXTERNAL (newdecl) |= DECL_EXTERNAL (olddecl);
  1306.       /* Do this after calling `commontype' so that default
  1307.      parameters don't confuse us.  */
  1308.       else if (TREE_CODE (newdecl) == FUNCTION_DECL
  1309.       && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
  1310.           != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  1311.     {
  1312.       tree ctype = NULL_TREE;
  1313.       if (TREE_CODE (newtype) == METHOD_TYPE)
  1314.         ctype = TYPE_METHOD_BASETYPE (newtype);
  1315.       else if (DECL_STATIC_FUNCTION_P (newdecl))
  1316.         ctype = DECL_STATIC_CONTEXT (newdecl);
  1317.       TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
  1318.                              TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
  1319.       TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
  1320.                              TYPE_RAISES_EXCEPTIONS (oldtype));
  1321.  
  1322.       if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
  1323.         {
  1324.           error_with_decl (newdecl, "declaration of `%s' raises different exceptions...");
  1325.           error_with_decl (olddecl, "...from previous declaration here");
  1326.         }
  1327.     }
  1328.       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
  1329.  
  1330.       /* Lay the type out, unless already done.  */
  1331.       if (oldtype != TREE_TYPE (newdecl))
  1332.     {
  1333.       if (TREE_TYPE (newdecl) != error_mark_node)
  1334.         layout_type (TREE_TYPE (newdecl));
  1335.       if (TREE_CODE (newdecl) != FUNCTION_DECL
  1336.           && TREE_CODE (newdecl) != TYPE_DECL
  1337.           && TREE_CODE (newdecl) != CONST_DECL)
  1338.         layout_decl (newdecl, 0);
  1339.     }
  1340.       else
  1341.     {
  1342.       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
  1343.       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
  1344.       DECL_SIZE_UNIT (newdecl) = DECL_SIZE_UNIT (olddecl);
  1345.       if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
  1346.         DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
  1347.     }
  1348.  
  1349.       /* Merge the type qualifiers.  */
  1350.       if (TREE_READONLY (newdecl))
  1351.     TREE_READONLY (olddecl) = 1;
  1352.       if (TREE_THIS_VOLATILE (newdecl))
  1353.     TREE_THIS_VOLATILE (olddecl) = 1;
  1354.  
  1355.       /* Merge the initialization information.  */
  1356.       if (DECL_INITIAL (newdecl) == 0)
  1357.     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  1358.       /* Keep the old rtl since we can safely use it.  */
  1359.       DECL_RTL (newdecl) = DECL_RTL (olddecl);
  1360.     }
  1361.   /* If cannot merge, then use the new type and qualifiers,
  1362.      and don't preserve the old rtl.  */
  1363.   else
  1364.     {
  1365.       /* Clean out any memory we had of the old declaration.  */
  1366.       tree oldstatic = value_member (olddecl, static_aggregates);
  1367.       if (oldstatic)
  1368.     TREE_VALUE (oldstatic) = error_mark_node;
  1369.  
  1370.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  1371.       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
  1372.       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
  1373.       TREE_VOLATILE (olddecl) = TREE_VOLATILE (newdecl);
  1374.     }
  1375.  
  1376.   /* Merge the storage class information.  */
  1377.   if (TREE_EXTERNAL (newdecl))
  1378.     {
  1379.       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
  1380.       TREE_EXTERNAL (newdecl) = TREE_EXTERNAL (olddecl);
  1381.  
  1382.       /* For functions, static overrides non-static.  */
  1383.       if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1384.     {
  1385.       TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
  1386.       /* This is since we don't automatically
  1387.          copy the attributes of NEWDECL into OLDDECL.  */
  1388.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  1389.       /* If this clears `static', clear it in the identifier too.  */
  1390.       if (! TREE_PUBLIC (olddecl))
  1391.         TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
  1392.     }
  1393.       else
  1394.     TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
  1395.     }
  1396.   else
  1397.     {
  1398.       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
  1399.       TREE_EXTERNAL (olddecl) = 0;
  1400.       /* A `const' which was not declared `extern' and is
  1401.      in static storage is invisible.  */
  1402.       if (TREE_CODE (newdecl) == VAR_DECL
  1403.       && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
  1404.       && ! DECL_EXTERNAL (newdecl))
  1405.     TREE_PUBLIC (newdecl) = 0;
  1406.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  1407.     }
  1408.   /* If either decl says `inline', this fn is inline,
  1409.      unless its definition was passed already.  */
  1410.   TREE_INLINE (olddecl) |= TREE_INLINE (newdecl);
  1411.  
  1412.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1413.     {
  1414.       if (new_is_definition)
  1415.     /* If defining a function declared with other language
  1416.        linkage, use the previously declared language linkage.  */
  1417.     DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  1418.       else
  1419.     {
  1420.       /* If redeclaring a builtin function, and not a definition,
  1421.          it stays built in.  */
  1422.       DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
  1423.       DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
  1424.       if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))
  1425.         /* Previously saved insns go together with
  1426.            the function's previous definition.  */
  1427.         DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  1428.       DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
  1429.     }
  1430.     }
  1431.  
  1432.   /* Now preserve various other info from the definition.  */
  1433.   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
  1434.   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
  1435.  
  1436.   /* Don't really know how much of the language-specific
  1437.      values we should copy from old to new.  */
  1438. #if 1
  1439.   if (DECL_LANG_SPECIFIC (olddecl))
  1440.     DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
  1441. #endif
  1442.  
  1443.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1444.     {
  1445.       int function_size;
  1446.       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
  1447.       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
  1448.  
  1449. #ifdef MERGED
  1450.       function_size = sizeof (struct tree_decl);
  1451. #else
  1452.       function_size = sizeof (struct tree_function_decl);
  1453. #endif
  1454.  
  1455.       /* Don't lose track of having output OLDDECL as GDB symbol.  */
  1456.       DECL_BLOCK_SYMTAB_ADDRESS (newdecl)
  1457.     = DECL_BLOCK_SYMTAB_ADDRESS (olddecl);
  1458.  
  1459.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  1460.          (char *) olddecl + sizeof (struct tree_common),
  1461.          function_size - sizeof (struct tree_common));
  1462.  
  1463.       if ((char *)newdecl == obstack_next_free (&permanent_obstack)
  1464.       - (function_size + sizeof (struct lang_decl)))
  1465.     {
  1466.       DECL_MAIN_VARIANT (newdecl) = olddecl;
  1467.       DECL_LANG_SPECIFIC (olddecl) = ol;
  1468.       bcopy (nl, ol, sizeof (struct lang_decl));
  1469.  
  1470.       obstack_free (&permanent_obstack, newdecl);
  1471.     }
  1472. #ifdef LANG_DECL_PERMANENT
  1473.       else if (LANG_DECL_PERMANENT (ol))
  1474.     {
  1475.       if (DECL_MAIN_VARIANT (olddecl) == olddecl)
  1476.         {
  1477.           /* Save these lang_decls that would otherwise be lost.  */
  1478.           extern tree free_lang_decl_chain;
  1479.           tree free_lang_decl = (tree) ol;
  1480.           TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
  1481.           free_lang_decl_chain = free_lang_decl;
  1482.         }
  1483.       else
  1484.         {
  1485.           /* Storage leak.  */
  1486.         }
  1487.     }
  1488. #else
  1489.       /* Storage leak.  */
  1490. #endif
  1491.     }
  1492.   else
  1493.     {
  1494.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  1495.          (char *) olddecl + sizeof (struct tree_common),
  1496.          sizeof (struct tree_decl) - sizeof (struct tree_common)
  1497.          + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
  1498.     }
  1499.  
  1500.   return 1;
  1501. }
  1502.  
  1503. /* Record a decl-node X as belonging to the current lexical scope.
  1504.    Check for errors (such as an incompatible declaration for the same
  1505.    name already seen in the same scope).
  1506.  
  1507.    Returns either X or an old decl for the same name.
  1508.    If an old decl is returned, it may have been smashed
  1509.    to agree with what X says.  */
  1510.  
  1511. tree
  1512. pushdecl (x)
  1513.      tree x;
  1514. {
  1515.   register tree t;
  1516.   register tree name = DECL_NAME (x);
  1517.   register struct binding_level *b = current_binding_level;
  1518.  
  1519.   if (name)
  1520.     {
  1521.       char *file;
  1522.       int line;
  1523.  
  1524.       t = lookup_name_current_level (name);
  1525.       if (t != 0 && t == error_mark_node)
  1526.     /* error_mark_node is 0 for a while during initialization!  */
  1527.     {
  1528.       t = 0;
  1529.       error_with_decl (x, "`%s' used prior to declaration");
  1530.     }
  1531.  
  1532.       if (t != 0)
  1533.     {
  1534.       tree cntxt = t;
  1535.       if (TREE_CODE (t) == PARM_DECL)
  1536.         {
  1537.           if (DECL_CONTEXT (t) == NULL_TREE)
  1538.         fatal ("parse errors have confused me too much");
  1539.           cntxt = DECL_CONTEXT (t);
  1540.         }
  1541.       file = DECL_SOURCE_FILE (t);
  1542.       line = DECL_SOURCE_LINE (t);
  1543.     }
  1544.  
  1545.       if (t != 0 && TREE_CODE (t) != TREE_CODE (x))
  1546.     {
  1547.       if (TREE_CODE (t) == TYPE_DECL)
  1548.         {
  1549. #ifdef BREAK_C_TAGS
  1550.           ;
  1551. #else
  1552.           warning ("type declaration of %s shadowed",
  1553.                IDENTIFIER_POINTER (name));
  1554. #endif
  1555.         }
  1556.       else if (TREE_CODE (x) == TYPE_DECL)
  1557.         {
  1558. #ifdef BREAK_C_TAGS
  1559.           ;
  1560. #else
  1561.           warning ("type declaration of %s shadows previous declaration",
  1562.                IDENTIFIER_POINTER (name));
  1563. #endif
  1564.         }
  1565.       else if (duplicate_decls (x, t))
  1566.         return t;
  1567.     }
  1568.       else if (t != 0 && duplicate_decls (x, t))
  1569.     {
  1570.       /* If this decl is `static' and an `extern' was seen previously,
  1571.          that is erroneous.  But don't complain if -traditional,
  1572.          since traditional compilers don't complain.
  1573.  
  1574.          Note that this does not apply to the C++ case of declaring
  1575.          a variable `extern const' and then later `const'.  */
  1576.       if (!flag_traditional && TREE_PUBLIC (name)
  1577.           && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x) && ! TREE_INLINE (x))
  1578.         {
  1579.           /* Due to interference in memory reclamation (X may be
  1580.          obstack-deallocated at this point, we must guard against
  1581.          one really special case).  */
  1582.           if (current_function_decl == x)
  1583.         current_function_decl = t;
  1584.           if (IDENTIFIER_IMPLICIT_DECL (name))
  1585.         warning ("`%s' was declared implicitly `extern' and later `static'",
  1586.              lang_printable_name (t));
  1587.           else
  1588.         warning ("`%s' was declared `extern' and later `static'",
  1589.              lang_printable_name (t));
  1590.           warning_with_file_and_line (file, line,
  1591.                       "previous declaration of `%s'",
  1592.                       lang_printable_name (t));
  1593.         }
  1594.       return t;
  1595.     }
  1596.  
  1597.       /* If declaring a type as a typedef, and the type has no known
  1598.      typedef name, install this TYPE_DECL as its typedef name.
  1599.  
  1600.      C++: If it had an anonymous aggregate or enum name,
  1601.      give it a `better' one.  */
  1602.       if (TREE_CODE (x) == TYPE_DECL)
  1603.     {
  1604.       tree name = TYPE_NAME (TREE_TYPE (x));
  1605.  
  1606.       if (name == NULL_TREE
  1607.           || (TREE_CODE (name) != TYPE_DECL
  1608. #ifndef BREAK_C_TAGS
  1609.           && current_lang_name == lang_name_cplusplus
  1610. #endif
  1611.           ))
  1612.         {
  1613.           /* If these are different names, make two equivalent
  1614.          definitions.  */
  1615.           TYPE_NAME (TREE_TYPE (x)) = x;
  1616.         }
  1617.       else
  1618.         {
  1619.           if (TREE_CODE (name) == TYPE_DECL)
  1620.         name = DECL_NAME (name);
  1621.           if (ANON_AGGRNAME_P (name))
  1622.         {
  1623.           /* do gratuitous C++ typedefing, and make sure that
  1624.              we access this type either through TREE_TYPE field
  1625.              or via the tags list.  */
  1626.           TYPE_NAME (TREE_TYPE (x)) = x;
  1627.           pushtag (name, TREE_TYPE (x));
  1628.         }
  1629.         }
  1630.     }
  1631.  
  1632.       /* Multiple external decls of the same identifier ought to match.  */
  1633.  
  1634.       if (TREE_EXTERNAL (x) && IDENTIFIER_GLOBAL_VALUE (name) != 0
  1635.       && (TREE_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
  1636.           || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
  1637.     {
  1638.       if (! comptypes (TREE_TYPE (x),
  1639.                TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)), 1))
  1640.         {
  1641.           warning_with_decl (x,
  1642.                  "type mismatch with previous external decl");
  1643.           warning_with_decl (IDENTIFIER_GLOBAL_VALUE (name),
  1644.                  "previous external decl of `%s'");
  1645.         }
  1646.     }
  1647.  
  1648.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  1649.      take effect at top level no matter where they are.  */
  1650.       if (flag_traditional && TREE_EXTERNAL (x)
  1651.       && lookup_name (name) == 0)
  1652.     b = global_binding_level;
  1653.  
  1654.       /* This name is new in its binding level.
  1655.      Install the new declaration and return it.  */
  1656.       if (b == global_binding_level)
  1657.     {
  1658.       /* Install a global value.  */
  1659.  
  1660.       /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
  1661.          A `const' which was not declared `extern' is invisible.  */
  1662.       if (TREE_CODE (x) == VAR_DECL
  1663.           && TREE_READONLY (x) && ! DECL_EXTERNAL (x))
  1664.         TREE_PUBLIC (x) = 0;
  1665.  
  1666.       /* If the first global decl has external linkage,
  1667.          warn if we later see static one.  */
  1668.       if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
  1669.         TREE_PUBLIC (name) = 1;
  1670.  
  1671.       IDENTIFIER_GLOBAL_VALUE (name) = x;
  1672.  
  1673.       /* Don't forget if the function was used via an implicit decl.  */
  1674.       if (IDENTIFIER_IMPLICIT_DECL (name)
  1675.           && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
  1676.         TREE_USED (x) = 1;
  1677.  
  1678.       /* Don't forget if its address was taken in that way.  */
  1679.       if (IDENTIFIER_IMPLICIT_DECL (name)
  1680.           && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
  1681.         TREE_ADDRESSABLE (x) = 1;
  1682.  
  1683.       /* Warn about mismatches against previous implicit decl.  */
  1684.       if (IDENTIFIER_IMPLICIT_DECL (name) != 0
  1685.           /* If this real decl matches the implicit, don't complain.  */
  1686.           && ! (TREE_CODE (x) == FUNCTION_DECL
  1687.             && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
  1688.         warning ("`%s' was previously implicitly declared to return `int'",
  1689.              lang_printable_name (x));
  1690.  
  1691.       /* If this decl is `static' and an `extern' was seen previously,
  1692.          that is erroneous.  */
  1693.       if (TREE_PUBLIC (name)
  1694.           && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x))
  1695.         {
  1696.           if (IDENTIFIER_IMPLICIT_DECL (name))
  1697.         warning ("`%s' was declared implicitly `extern' and later `static'",
  1698.              lang_printable_name (x));
  1699.           else
  1700.         warning ("`%s' was declared `extern' and later `static'",
  1701.              lang_printable_name (x));
  1702.         }
  1703.     }
  1704.       else
  1705.     {
  1706.       /* Here to install a non-global value.  */
  1707.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  1708.       tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
  1709.       IDENTIFIER_LOCAL_VALUE (name) = x;
  1710.  
  1711.       /* If this is an extern function declaration, see if we
  1712.          have a global definition for the function.  */
  1713.       if (oldlocal == 0
  1714.           && oldglobal != 0
  1715.           && TREE_CODE (x) == FUNCTION_DECL
  1716.           && TREE_CODE (oldglobal) == FUNCTION_DECL)
  1717.         {
  1718.           /* We have one.  Their types must agree.  */
  1719.           if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
  1720.         warning_with_decl (x, "local declaration of `%s' doesn't match global one");
  1721.           /* If the global one is inline, make the local one inline.  */
  1722.           else if (TREE_INLINE (oldglobal)
  1723.                || DECL_FUNCTION_CODE (oldglobal) != NOT_BUILT_IN
  1724.                || (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
  1725.                && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0))
  1726.         IDENTIFIER_LOCAL_VALUE (name) = oldglobal;
  1727.         }
  1728.       /* If we have a local external declaration,
  1729.          and no file-scope declaration has yet been seen,
  1730.          then if we later have a file-scope decl it must not be static.  */
  1731.       if (oldlocal == 0
  1732.           && oldglobal == 0
  1733.           && TREE_EXTERNAL (x)
  1734.           && TREE_PUBLIC (x))
  1735.         {
  1736.           TREE_PUBLIC (name) = 1;
  1737.         }
  1738.  
  1739.       if (TREE_INLINE (x))
  1740.         /* Inline decls shadow nothing.  */;
  1741.  
  1742.       /* Warn if shadowing an argument at the top level of the body.  */
  1743.       else if (oldlocal != 0 && !TREE_EXTERNAL (x)
  1744.           && TREE_CODE (oldlocal) == PARM_DECL
  1745.           && TREE_CODE (x) != PARM_DECL
  1746.           /* The parm level is two levels above the first user-visible
  1747.          level.  One level was created for parm cleanups, the
  1748.          other declared by the user.  */
  1749.           && current_binding_level->level_chain->level_chain->parm_flag == 1)
  1750.         warning ("declaration of `%s' shadows a parameter",
  1751.              IDENTIFIER_POINTER (name));
  1752.  
  1753.       /* Maybe warn if shadowing something else.  */
  1754.       else if (warn_shadow && !TREE_EXTERNAL (x))
  1755.         {
  1756.           char *warnstring = 0;
  1757.  
  1758.           if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
  1759.         warnstring = "declaration of `%s' shadows a parameter";
  1760.           else if (IDENTIFIER_CLASS_VALUE (name) != 0)
  1761.         warnstring = "declaration of `%s' shadows a member of `this'";
  1762.           else if (oldlocal != 0)
  1763.         warnstring = "declaration of `%s' shadows previous local";
  1764.           else if (oldglobal != 0)
  1765.         warnstring = "declaration of `%s' shadows global declaration";
  1766.  
  1767.           if (warnstring)
  1768.         warning (warnstring, IDENTIFIER_POINTER (name));
  1769.         }
  1770.  
  1771.       /* If storing a local value, there may already be one (inherited).
  1772.          If so, record it for restoration when this binding level ends.  */
  1773.       if (oldlocal != 0)
  1774.         b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  1775.     }
  1776.  
  1777.       /* Keep count of variables in this level with incomplete type.  */
  1778.       if (TYPE_SIZE (TREE_TYPE (x)) == 0
  1779.       && (IS_AGGR_TYPE (TREE_TYPE (x))
  1780.           || (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
  1781.           && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (x))))))
  1782.     {
  1783.       if (++b->n_incomplete == 0)
  1784.         error ("too many incomplete variables at this point");
  1785.     }
  1786.     }
  1787.  
  1788.   /* Put decls on list in reverse order.
  1789.      We will reverse them later if necessary.  */
  1790.   TREE_CHAIN (x) = b->names;
  1791.   b->names = x;
  1792.  
  1793.   return x;
  1794. }
  1795.  
  1796. /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
  1797.    if appropriate.  */
  1798. tree
  1799. pushdecl_top_level (x)
  1800.      tree x;
  1801. {
  1802.   register tree t;
  1803.   register struct binding_level *b = current_binding_level;
  1804.  
  1805.   current_binding_level = global_binding_level;
  1806.   t = pushdecl (x);
  1807.   current_binding_level = b;
  1808.   return t;
  1809. }
  1810.  
  1811. /* Make the declaration of X appear in CLASS scope.  */
  1812. tree
  1813. pushdecl_class_level (x)
  1814.      tree x;
  1815. {
  1816.   register tree name = DECL_NAME (x);
  1817.  
  1818.   if (name)
  1819.     {
  1820.       tree oldclass = IDENTIFIER_CLASS_VALUE (name);
  1821.       if (oldclass)
  1822.     class_binding_level->class_shadowed
  1823.       = tree_cons (name, oldclass, class_binding_level->class_shadowed);
  1824.       IDENTIFIER_CLASS_VALUE (name) = x;
  1825.       obstack_ptr_grow (&decl_obstack, x);
  1826.     }      
  1827.   return x;
  1828. }
  1829.  
  1830. /* Tell caller how to interpret a TREE_LIST which contains
  1831.    chains of FUNCTION_DECLS.  */
  1832. int
  1833. overloaded_globals_p (list)
  1834.      tree list;
  1835. {
  1836.   assert (TREE_CODE (list) == TREE_LIST);
  1837.  
  1838.   /* Don't commit caller to seeing them as globals.  */
  1839.   if (TREE_NONLOCAL (list))
  1840.     return -1;
  1841.   /* Do commit caller to seeing them as globals.  */
  1842.   if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
  1843.     return 1;
  1844.   /* Do commit caller to not seeing them as globals.  */
  1845.   return 0;
  1846. }
  1847.  
  1848. /* DECL is a FUNCTION_DECL which may have other definitions already in place.
  1849.    We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_ORIGINAL_NAME (DECL))
  1850.    point to a list of all the things that want to be referenced by that name.
  1851.    It is then up to the users of that name to decide what to do with that
  1852.    list.  */
  1853. void
  1854. push_overloaded_decl (decl)
  1855.      tree decl;
  1856. {
  1857.   tree orig_name = DECL_ORIGINAL_NAME (decl);
  1858.   tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name);
  1859.  
  1860.   DECL_OVERLOADED (decl) = 1;
  1861.   if (glob && TREE_CODE (glob) != TREE_LIST)
  1862.     {
  1863.       if (DECL_LANGUAGE (decl) == lang_c)
  1864.     {
  1865.       if (TREE_CODE (glob) == FUNCTION_DECL)
  1866.         {
  1867.           if (DECL_LANGUAGE (glob) == lang_c)
  1868.         {
  1869.           error_with_decl (decl, "C-language function `%s' overloaded here");
  1870.           error_with_decl (glob, "Previous C-language version of this function was `%s'");
  1871.         }
  1872.         }
  1873.       else abort ();
  1874.     }
  1875.       if (! flag_traditional
  1876.       && TREE_PERMANENT (glob) == 1
  1877.       && current_binding_level != global_binding_level)
  1878.     overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
  1879.       if (TREE_CODE (glob) == FUNCTION_DECL
  1880.       && DECL_LANGUAGE (glob) != DECL_LANGUAGE (decl)
  1881.       && comptypes (TREE_TYPE (glob), TREE_TYPE (decl), 1))
  1882.     {
  1883.       error_with_decl (decl, "conflicting language contexts for declaration of `%s';");
  1884.       error_with_decl (glob, "conflicts with previous declaration here");
  1885.     }
  1886.       glob = tree_cons (DECL_NAME (glob), glob, NULL_TREE);
  1887.       glob = tree_cons (TREE_PURPOSE (glob), decl, glob);
  1888.       IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
  1889.       TREE_TYPE (glob) = unknown_type_node;
  1890.       return;
  1891.     }
  1892.   if (glob)
  1893.     {
  1894.       tree tmp, name;
  1895.  
  1896.       if (TREE_VALUE (glob) == NULL_TREE)
  1897.     {
  1898.       TREE_VALUE (glob) = decl;
  1899.       return;
  1900.     }
  1901.       name = DECL_NAME (decl);
  1902.       for (tmp = glob; tmp; tmp = TREE_CHAIN (tmp))
  1903.     {
  1904.       if (TREE_CODE (TREE_VALUE (tmp)) == FUNCTION_DECL
  1905.           && DECL_LANGUAGE (TREE_VALUE (tmp)) != DECL_LANGUAGE (decl)
  1906.           && comptypes (TREE_TYPE (TREE_VALUE (tmp)), TREE_TYPE (decl), 1))
  1907.         {
  1908.           error_with_decl (decl, "conflicting language contexts for declaration of `%s';");
  1909.           error_with_decl (TREE_VALUE (tmp), "conflicts with previous declaration here");
  1910.         }
  1911.       if (DECL_NAME (TREE_VALUE (tmp)) == name)
  1912.         return;
  1913.     }
  1914.     }
  1915.  
  1916.   if (DECL_LANGUAGE (decl) == lang_c)
  1917.     {
  1918.       tree decls = glob;
  1919.       while (decls && DECL_LANGUAGE (TREE_VALUE (decls)) == lang_cplusplus)
  1920.     decls = TREE_CHAIN (decls);
  1921.       if (decls)
  1922.     {
  1923.       error_with_decl (decl, "C-language function `%s' overloaded here");
  1924.       error_with_decl (TREE_VALUE (decls), "Previous C-language version of this function was `%s'");
  1925.     }
  1926.     }
  1927.  
  1928.   if (! flag_traditional
  1929.       && (glob == 0 || TREE_PERMANENT (glob) == 1)
  1930.       && current_binding_level != global_binding_level)
  1931.     overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
  1932.   glob = tree_cons (orig_name, decl, glob);
  1933.   IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
  1934.   TREE_TYPE (glob) = unknown_type_node;
  1935. }
  1936.  
  1937. /* Generate an implicit declaration for identifier FUNCTIONID
  1938.    as a function of type int ().  Print a warning if appropriate.  */
  1939.  
  1940. tree
  1941. implicitly_declare (functionid)
  1942.      tree functionid;
  1943. {
  1944.   register tree decl;
  1945.   int temp = allocation_temporary_p ();
  1946.  
  1947.   /* Save the decl permanently so we can warn if definition follows.  */
  1948.   if (temp && (flag_traditional || !warn_implicit))
  1949.     end_temporary_allocation ();
  1950.  
  1951.   /* We used to reuse an old implicit decl here,
  1952.      but this loses with inline functions because it can clobber
  1953.      the saved decl chains.  */
  1954. /*  if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
  1955.     decl = IDENTIFIER_IMPLICIT_DECL (functionid);
  1956.   else  */
  1957.     decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
  1958.  
  1959.   TREE_EXTERNAL (decl) = 1;
  1960.   TREE_PUBLIC (decl) = 1;
  1961.  
  1962.   /* ANSI standard says implicit declarations are in the innermost block.
  1963.      So we record the decl in the standard fashion.
  1964.      If flag_traditional is set, pushdecl does it top-level.  */
  1965.   pushdecl (decl);
  1966.   rest_of_decl_compilation (decl, 0, 0, 0);
  1967.  
  1968.   if (warn_implicit
  1969.       /* Only one warning per identifier.  */
  1970.       && IDENTIFIER_IMPLICIT_DECL (functionid) == 0)
  1971.     warning ("implicit declaration of function `%s'",
  1972.          IDENTIFIER_POINTER (functionid));
  1973.  
  1974.   SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
  1975.  
  1976.   if (temp && (flag_traditional || ! warn_implicit))
  1977.     resume_temporary_allocation ();
  1978.  
  1979.   return decl;
  1980. }
  1981.  
  1982. /* Return zero if the declaration NEWDECL is valid
  1983.    when the declaration OLDDECL (assumed to be for the same name)
  1984.    has already been seen.
  1985.    Otherwise return an error message format string with a %s
  1986.    where the identifier should go.  */
  1987.  
  1988. static char *
  1989. redeclaration_error_message (newdecl, olddecl)
  1990.      tree newdecl, olddecl;
  1991. {
  1992.   if (TREE_CODE (newdecl) == TYPE_DECL)
  1993.     {
  1994.       /* Because C++ can put things into name space for free,
  1995.      constructs like "typedef struct foo { ... } foo"
  1996.      would look like an erroneous redeclaration.  */
  1997.       if (TREE_TYPE (olddecl) == TREE_TYPE (newdecl))
  1998.     return 0;
  1999.       else
  2000.     return "redefinition of `%s'";
  2001.     }
  2002.   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2003.     {
  2004.       /* Declarations of functions can insist on internal linkage
  2005.      but they can't be inconsistent with internal linkage,
  2006.      so there can be no error on that account.
  2007.      However defining the same name twice is no good.  */
  2008.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
  2009.       /* However, defining once as extern inline and a second
  2010.          time in another way is ok.  */
  2011.       && !(TREE_INLINE (olddecl) && TREE_EXTERNAL (olddecl)
  2012.            && !(TREE_INLINE (newdecl) && TREE_EXTERNAL (newdecl))))
  2013.     {
  2014.       if (DECL_LANG_SPECIFIC (olddecl)
  2015.           && DECL_COMPILER_GENERATED_P (olddecl))
  2016.         return "`%s' not declared in class";
  2017.       else
  2018.         return "redefinition of `%s'";
  2019.     }
  2020.       return 0;
  2021.     }
  2022.   else if (current_binding_level == global_binding_level)
  2023.     {
  2024.       /* Objects declared at top level:  */
  2025.       /* If at least one is a reference, it's ok.  */
  2026.       if (TREE_EXTERNAL (newdecl) || TREE_EXTERNAL (olddecl))
  2027.     return 0;
  2028.       /* Reject two definitions.  */
  2029.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
  2030.     return "redefinition of `%s'";
  2031.       /* Now we have two tentative defs, or one tentative and one real def.  */
  2032.       /* Insist that the linkage match.  */
  2033.       if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
  2034.     return "conflicting declarations of `%s'";
  2035.       return 0;
  2036.     }
  2037.   else
  2038.     {
  2039.       /* Objects declared with block scope:  */
  2040.       /* Reject two definitions, and reject a definition
  2041.      together with an external reference.  */
  2042.       if (!(TREE_EXTERNAL (newdecl) && TREE_EXTERNAL (olddecl)))
  2043.     return "redeclaration of `%s'";
  2044.       return 0;
  2045.     }
  2046. }
  2047.  
  2048. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  2049.    Create one if none exists so far for the current function.
  2050.    This function is called for both label definitions and label references.  */
  2051.  
  2052. tree
  2053. lookup_label (id)
  2054.      tree id;
  2055. {
  2056.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  2057.  
  2058.   if ((decl == 0
  2059.       || DECL_SOURCE_LINE (decl) == 0)
  2060.       && (named_label_uses == 0
  2061.       || TREE_PURPOSE (named_label_uses) != current_binding_level->names
  2062.       || TREE_VALUE (named_label_uses) != decl))
  2063.     {
  2064.       named_label_uses
  2065.     = tree_cons (current_binding_level->names, decl, named_label_uses);
  2066.       TREE_TYPE (named_label_uses) = (tree)current_binding_level;
  2067.     }
  2068.  
  2069.   if (decl != 0)
  2070.     return decl;
  2071.  
  2072.   /* By giving the label type `void *', we can use it as a value.  */
  2073.   decl = build_decl (LABEL_DECL, id, ptr_type_node);
  2074.   DECL_MODE (decl) = VOIDmode;
  2075.   /* Mark that the label's definition has not been seen.  */
  2076.   DECL_SOURCE_LINE (decl) = 0;
  2077.  
  2078.   SET_IDENTIFIER_LABEL_VALUE (id, decl);
  2079.  
  2080.   named_labels = tree_cons (NULL_TREE, decl, named_labels);
  2081.   TREE_VALUE (named_label_uses) = decl;
  2082.  
  2083.   return decl;
  2084. }
  2085.  
  2086. /* Define a label, specifying the location in the source file.
  2087.    Return the LABEL_DECL node for the label, if the definition is valid.
  2088.    Otherwise return 0.  */
  2089.  
  2090. tree
  2091. define_label (filename, line, name)
  2092.      char *filename;
  2093.      int line;
  2094.      tree name;
  2095. {
  2096.   tree decl = lookup_label (name);
  2097.  
  2098.   /* After labels, make any new cleanups go into their
  2099.      own new (temporary) binding contour.  */
  2100.   current_binding_level->more_cleanups_ok = 0;
  2101.  
  2102.   if (DECL_SOURCE_LINE (decl) != 0)
  2103.     {
  2104.       error_with_decl (decl, "duplicate label `%s'");
  2105.       return 0;
  2106.     }
  2107.   else
  2108.     {
  2109.       tree uses, prev;
  2110.  
  2111.       /* Mark label as having been defined.  */
  2112.       DECL_SOURCE_FILE (decl) = filename;
  2113.       DECL_SOURCE_LINE (decl) = line;
  2114.  
  2115.       for (prev = 0, uses = named_label_uses;
  2116.        uses;
  2117.        prev = uses, uses = TREE_CHAIN (uses))
  2118.     if (TREE_VALUE (uses) == decl)
  2119.       {
  2120.         struct binding_level *b = current_binding_level;
  2121.         while (1)
  2122.           {
  2123.         tree new_decls = b->names;
  2124.         tree old_decls = ((tree)b == TREE_TYPE (uses)
  2125.                   ? TREE_PURPOSE (uses) : NULL_TREE);
  2126.         while (new_decls != old_decls)
  2127.           {
  2128.             if (TREE_CODE (new_decls) == VAR_DECL
  2129.             /* Don't complain about crossing initialization
  2130.                of temporaries.  They can't be accessed,
  2131.                and they should be cleaned up
  2132.                by the time we get to the label.  */
  2133.             && ! TEMP_NAME_P (DECL_NAME (new_decls))
  2134.             && ((DECL_INITIAL (new_decls) != NULL_TREE
  2135.                  && DECL_INITIAL (new_decls) != error_mark_node)
  2136.                 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  2137.               {
  2138.             if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
  2139.               error_with_decl (decl, "invalid jump to label `%s'");
  2140.             SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
  2141.             error_with_decl (new_decls, "crosses initialization of `%s'");
  2142.               }
  2143.             new_decls = TREE_CHAIN (new_decls);
  2144.           }
  2145.         if ((tree)b == TREE_TYPE (uses))
  2146.           break;
  2147.         b = b->level_chain;
  2148.           }
  2149.  
  2150.         if (prev)
  2151.           TREE_CHAIN (prev) = TREE_CHAIN (uses);
  2152.         else
  2153.           named_label_uses = TREE_CHAIN (uses);
  2154.       }
  2155.       return decl;
  2156.     }
  2157. }
  2158.  
  2159. /* Same, but for CASE labels.  */
  2160. void
  2161. define_case_label (decl)
  2162.      tree decl;
  2163. {
  2164.   /* After labels, make any new cleanups go into their
  2165.      own new (temporary) binding contour.  */
  2166.  
  2167.   current_binding_level->more_cleanups_ok = 0;
  2168. }
  2169.  
  2170. /* Return the list of declarations of the current level.
  2171.    Note that this list is in reverse order unless/until
  2172.    you nreverse it; and when you do nreverse it, you must
  2173.    store the result back using `storedecls' or you will lose.  */
  2174.  
  2175. tree
  2176. getdecls ()
  2177. {
  2178.   return current_binding_level->names;
  2179. }
  2180.  
  2181. /* Return the list of type-tags (for structs, etc) of the current level.  */
  2182.  
  2183. tree
  2184. gettags ()
  2185. {
  2186.   return current_binding_level->tags;
  2187. }
  2188.  
  2189. /* Store the list of declarations of the current level.
  2190.    This is done for the parameter declarations of a function being defined,
  2191.    after they are modified in the light of any missing parameters.  */
  2192.  
  2193. static void
  2194. storedecls (decls)
  2195.      tree decls;
  2196. {
  2197.   current_binding_level->names = decls;
  2198. }
  2199.  
  2200. /* Similarly, store the list of tags of the current level.  */
  2201.  
  2202. static void
  2203. storetags (tags)
  2204.      tree tags;
  2205. {
  2206.   current_binding_level->tags = tags;
  2207. }
  2208.  
  2209. /* Given NAME, an IDENTIFIER_NODE,
  2210.    return the structure (or union or enum) definition for that name.
  2211.    Searches binding levels from BINDING_LEVEL up to the global level.
  2212.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  2213.    (but skips any tag-transparent contexts to find one that is
  2214.    meaningful for tags).
  2215.    FORM says which kind of type the caller wants;
  2216.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  2217.    If the wrong kind of type is found, an error is reported.  */
  2218.  
  2219. static tree
  2220. lookup_tag (form, name, binding_level, thislevel_only)
  2221.      enum tree_code form;
  2222.      struct binding_level *binding_level;
  2223.      tree name;
  2224.      int thislevel_only;
  2225. {
  2226.   register struct binding_level *level;
  2227.  
  2228.   for (level = binding_level; level; level = level->level_chain)
  2229.     {
  2230.       register tree tail;
  2231.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  2232.     {
  2233.       if (TREE_PURPOSE (tail) == name)
  2234.         {
  2235.           if (TREE_CODE (TREE_VALUE (tail)) != form)
  2236.         {
  2237.           /* Definition isn't the kind we were looking for.  */
  2238.           error ("`%s' defined as wrong kind of tag",
  2239.              IDENTIFIER_POINTER (name));
  2240.         }
  2241.           return TREE_VALUE (tail);
  2242.         }
  2243.     }
  2244.       if (thislevel_only && ! level->tag_transparent)
  2245.     return NULL_TREE;
  2246.       if (current_class_type && level->level_chain == global_binding_level)
  2247.     {
  2248.       /* Try looking in this class's tags before heading into
  2249.          global binding level.  */
  2250.       tree these_tags = CLASSTYPE_TAGS (current_class_type);
  2251.       while (these_tags)
  2252.         {
  2253.           if (TREE_PURPOSE (these_tags) == name)
  2254.         {
  2255.           if (TREE_CODE (TREE_VALUE (these_tags)) != form)
  2256.             {
  2257.               error ("`%s' defined as wrong kind of tag in class scope",
  2258.                  IDENTIFIER_POINTER (name));
  2259.             }
  2260.           return TREE_VALUE (tail);
  2261.         }
  2262.           these_tags = TREE_CHAIN (these_tags);
  2263.         }
  2264.     }
  2265.     }
  2266.   return NULL_TREE;
  2267. }
  2268.  
  2269. /* Given a type, find the tag that was defined for it and return the tag name.
  2270.    Otherwise return 0.  However, the value can never be 0
  2271.    in the cases in which this is used.
  2272.  
  2273.    C++: If NAME is non-zero, this is the new name to install.  This is
  2274.    done when replacing anonymous tags with real tag names.  */
  2275.  
  2276. static tree
  2277. lookup_tag_reverse (type, name)
  2278.      tree type;
  2279.      tree name;
  2280. {
  2281.   register struct binding_level *level;
  2282.  
  2283.   for (level = current_binding_level; level; level = level->level_chain)
  2284.     {
  2285.       register tree tail;
  2286.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  2287.     {
  2288.       if (TREE_VALUE (tail) == type)
  2289.         {
  2290.           if (name)
  2291.         TREE_PURPOSE (tail) = name;
  2292.           return TREE_PURPOSE (tail);
  2293.         }
  2294.     }
  2295.     }
  2296.   return NULL_TREE;
  2297. }
  2298.  
  2299. /* Given type TYPE which was not declared in C++ language context,
  2300.    attempt to find a name by which it is refered.  */
  2301. tree
  2302. typedecl_for_tag (tag)
  2303.      tree tag;
  2304. {
  2305.   struct binding_level *b = current_binding_level;
  2306.  
  2307.   if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
  2308.     return TYPE_NAME (tag);
  2309.  
  2310.   while (b)
  2311.     {
  2312.       tree decls = b->names;
  2313.       while (decls)
  2314.     {
  2315.       if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
  2316.         break;
  2317.       decls = TREE_CHAIN (decls);
  2318.     }
  2319.       if (decls)
  2320.     return decls;
  2321.       b = b->level_chain;
  2322.     }
  2323.   return NULL_TREE;
  2324. }
  2325.  
  2326. /* Look up NAME in the current binding level and its superiors
  2327.    in the namespace of variables, functions and typedefs.
  2328.    Return a ..._DECL node of some kind representing its definition,
  2329.    or return 0 if it is undefined.  */
  2330.  
  2331. tree
  2332. lookup_name (name)
  2333.      tree name;
  2334. {
  2335.   register tree val;
  2336.   if (current_binding_level != global_binding_level
  2337.       && IDENTIFIER_LOCAL_VALUE (name))
  2338.     val = IDENTIFIER_LOCAL_VALUE (name);
  2339.   /* In C++ class fields are between local and global scope,
  2340.      just before the global scope.  */
  2341.   else if (current_class_type)
  2342.     {
  2343.       if (IDENTIFIER_CLASS_VALUE (name))
  2344.     val = IDENTIFIER_CLASS_VALUE (name);
  2345.       else if (TYPE_SIZE (current_class_type) == 0
  2346.            && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
  2347.     {
  2348.       /* Try to find values from base classes
  2349.          if we are presently defining a type.
  2350.          We are presently only interested in TYPE_DECLs.  */
  2351.       val = lookup_field (current_class_type, name, 0);
  2352.       if (val == error_mark_node)
  2353.         return val;
  2354.       if (val && TREE_CODE (val) != TYPE_DECL)
  2355.         val = NULL_TREE;
  2356.       else if (val == NULL_TREE)
  2357.         val = IDENTIFIER_GLOBAL_VALUE (name);
  2358.     }
  2359.       else
  2360.     val = IDENTIFIER_GLOBAL_VALUE (name);
  2361.     }
  2362.   else
  2363.     val = IDENTIFIER_GLOBAL_VALUE (name);
  2364.   if (val && TREE_TYPE (val) == error_mark_node)
  2365.     return error_mark_node;
  2366.   return val;
  2367. }
  2368.  
  2369. /* Similar to `lookup_name' but look only at current binding level.  */
  2370.  
  2371. static tree
  2372. lookup_name_current_level (name)
  2373.      tree name;
  2374. {
  2375.   register tree t;
  2376.  
  2377.   if (current_binding_level == global_binding_level)
  2378.     return IDENTIFIER_GLOBAL_VALUE (name);
  2379.  
  2380.   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
  2381.     return 0;
  2382.  
  2383.   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
  2384.     if (DECL_NAME (t) == name)
  2385.       break;
  2386.  
  2387.   return t;
  2388. }
  2389.  
  2390. static int sigsegv ()
  2391. {
  2392.   error ("Segmentation violation");
  2393.   signal (SIGSEGV, SIG_DFL);
  2394. }
  2395.  
  2396. /* Create the predefined scalar types of C,
  2397.    and some nodes representing standard constants (0, 1, (void *)0).
  2398.    Initialize the global binding level.
  2399.    Make definitions for built-in primitive functions.  */
  2400.  
  2401. union tree_node ERROR_MARK_NODE;
  2402.  
  2403. void
  2404. init_decl_processing ()
  2405. {
  2406.   register tree endlink, int_endlink, double_endlink, ptr_endlink;
  2407.  
  2408.   /* Have to make these distinct before we try using them.  */
  2409.   lang_name_cplusplus = get_identifier ("C++");
  2410.   lang_name_c = get_identifier ("C");
  2411.  
  2412.   /* Initially, C.  */
  2413.   current_lang_name = lang_name_c;
  2414.  
  2415.   current_function_decl = NULL_TREE;
  2416.   named_labels = NULL_TREE;
  2417.   named_label_uses = NULL_TREE;
  2418.   current_binding_level = NULL_BINDING_LEVEL;
  2419.   free_binding_level = NULL_BINDING_LEVEL;
  2420.  
  2421.   if (write_symbols == GDB_DEBUG)
  2422.     fatal ("GNU C++ does not support GDB symbol info yet, use -g");
  2423.  
  2424.   /* Handle signals.  */
  2425.   signal (SIGSEGV, sigsegv);
  2426.  
  2427.   obstack_init (&decl_obstack);
  2428.  
  2429.   /* Must lay these out before anything else gets laid out.  */
  2430. #if 0
  2431.   error_mark_node = make_node (ERROR_MARK);
  2432. #else
  2433. #undef error_mark_node
  2434.   error_mark_node = &ERROR_MARK_NODE;
  2435. #define error_mark_node (&ERROR_MARK_NODE)
  2436.   TREE_PERMANENT (error_mark_node) = 1;
  2437. #endif
  2438.   TREE_TYPE (error_mark_node) = error_mark_node;
  2439.   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
  2440.   TREE_TYPE (error_mark_list) = error_mark_node;
  2441.  
  2442.   pushlevel (0);    /* make the binding_level structure for global names.  */
  2443.   global_binding_level = current_binding_level;
  2444.  
  2445.   value_identifier = get_identifier ("<value>");
  2446.   this_identifier = get_identifier (THIS_NAME);
  2447.   in_charge_identifier = get_identifier (IN_CHARGE_NAME);
  2448.  
  2449.   /* Define `int' and `char' first so that dbx will output them first.  */
  2450.  
  2451.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  2452.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_INT])
  2453.     = pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],
  2454.                 integer_type_node));
  2455.  
  2456.   /* Define `char', which is like either `signed char' or `unsigned char'
  2457.      but not the same as either.  */
  2458.  
  2459.   char_type_node =
  2460.     (flag_signed_char
  2461.      ? make_signed_type (CHAR_TYPE_SIZE)
  2462.      : make_unsigned_type (CHAR_TYPE_SIZE));
  2463.  
  2464.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_CHAR])
  2465.     = pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),
  2466.                 char_type_node));
  2467.  
  2468.   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
  2469.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_LONG])
  2470.     = pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),
  2471.                 long_integer_type_node));
  2472.  
  2473.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  2474.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_UNSIGNED])
  2475.     = pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
  2476.                 unsigned_type_node));
  2477.  
  2478.   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
  2479.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),
  2480.             long_unsigned_type_node));
  2481.  
  2482.   /* `unsigned long' or `unsigned int' is the standard type for sizeof.
  2483.      Traditionally, use a signed type.  */
  2484.   if (INT_TYPE_SIZE != BITS_PER_WORD)
  2485.     sizetype = flag_traditional ? long_integer_type_node : long_unsigned_type_node;
  2486.   else
  2487.     sizetype = flag_traditional ? integer_type_node : unsigned_type_node;
  2488.  
  2489.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  2490.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  2491.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  2492.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  2493.   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
  2494.  
  2495.   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
  2496.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_SHORT])
  2497.     = pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),
  2498.                 short_integer_type_node));
  2499.  
  2500.   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
  2501.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"),
  2502.             long_long_integer_type_node));
  2503.   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
  2504.   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short int"),
  2505.             short_unsigned_type_node));
  2506.   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
  2507.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"),
  2508.             long_long_unsigned_type_node));
  2509.  
  2510.   /* Define both `signed char' and `unsigned char'.  */
  2511.   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
  2512.   pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),
  2513.             signed_char_type_node));
  2514.   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  2515.   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),
  2516.             unsigned_char_type_node));
  2517.  
  2518.   float_type_node = make_node (REAL_TYPE);
  2519.   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
  2520.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_FLOAT])
  2521.     = pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
  2522.                 float_type_node));
  2523.   layout_type (float_type_node);
  2524.  
  2525.   double_type_node = make_node (REAL_TYPE);
  2526.   TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
  2527.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_DOUBLE])
  2528.     = pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
  2529.                 double_type_node));
  2530.   layout_type (double_type_node);
  2531.  
  2532.   long_double_type_node = make_node (REAL_TYPE);
  2533.   TYPE_PRECISION (long_double_type_node) = DOUBLE_TYPE_SIZE;
  2534.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),
  2535.             long_double_type_node));
  2536.   layout_type (long_double_type_node);
  2537.  
  2538.   integer_zero_node = build_int_2 (0, 0);
  2539.   TREE_TYPE (integer_zero_node) = integer_type_node;
  2540.   integer_one_node = build_int_2 (1, 0);
  2541.   TREE_TYPE (integer_one_node) = integer_type_node;
  2542.   integer_two_node = build_int_2 (2, 0);
  2543.   TREE_TYPE (integer_two_node) = integer_type_node;
  2544.   integer_three_node = build_int_2 (3, 0);
  2545.   TREE_TYPE (integer_three_node) = integer_type_node;
  2546.   empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
  2547.  
  2548.   size_zero_node = build_int_2 (0, 0);
  2549.   TREE_TYPE (size_zero_node) = sizetype;
  2550.   size_one_node = build_int_2 (1, 0);
  2551.   TREE_TYPE (size_one_node) = sizetype;
  2552.  
  2553.   void_type_node = make_node (VOID_TYPE);
  2554.   IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) RID_VOID])
  2555.     = pushdecl (build_decl (TYPE_DECL,
  2556.                 ridpointers[(int) RID_VOID], void_type_node));
  2557.   layout_type (void_type_node); /* Uses integer_zero_node.  */
  2558.   void_list_node = build_tree_list (NULL_TREE, void_type_node);
  2559.   TREE_PARMLIST (void_list_node) = 1;
  2560.  
  2561.   null_pointer_node = build_int_2 (0, 0);
  2562.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  2563.   layout_type (TREE_TYPE (null_pointer_node));
  2564.  
  2565.   string_type_node = build_pointer_type (char_type_node);
  2566.  
  2567.   /* make a type for arrays of 256 characters.
  2568.      256 is picked randomly because we have a type for integers from 0 to 255.
  2569.      With luck nothing will ever really depend on the length of this
  2570.      array type.  */
  2571.   char_array_type_node
  2572.     = build_array_type (char_type_node, unsigned_char_type_node);
  2573.   /* Likewise for arrays of ints.  */
  2574.   int_array_type_node
  2575.     = build_array_type (integer_type_node, unsigned_char_type_node);
  2576.  
  2577.   default_function_type
  2578.     = build_function_type (integer_type_node, NULL_TREE);
  2579.   build_pointer_type (default_function_type);
  2580.  
  2581.   ptr_type_node = build_pointer_type (void_type_node);
  2582.   endlink = void_list_node;
  2583.   int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
  2584.   double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
  2585.   ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
  2586.  
  2587.   double_ftype_double
  2588.     = build_function_type (double_type_node, double_endlink);
  2589.  
  2590.   double_ftype_double_double
  2591.     = build_function_type (double_type_node,
  2592.                tree_cons (NULL_TREE, double_type_node, double_endlink));
  2593.  
  2594.   int_ftype_int
  2595.     = build_function_type (integer_type_node, int_endlink);
  2596.  
  2597.   long_ftype_long
  2598.     = build_function_type (long_integer_type_node,
  2599.                tree_cons (NULL_TREE, long_integer_type_node, endlink));
  2600.  
  2601.   void_ftype_ptr_ptr_int
  2602.     = build_function_type (void_type_node,
  2603.                tree_cons (NULL_TREE, ptr_type_node,
  2604.                       tree_cons (NULL_TREE, ptr_type_node,
  2605.                          int_endlink)));
  2606.  
  2607.   int_ftype_ptr_ptr_int
  2608.     = build_function_type (integer_type_node, TYPE_ARG_TYPES (void_ftype_ptr_ptr_int));
  2609.  
  2610.   void_ftype_ptr_int_int
  2611.     = build_function_type (void_type_node,
  2612.                tree_cons (NULL_TREE, ptr_type_node,
  2613.                       tree_cons (NULL_TREE, integer_type_node,
  2614.                          int_endlink)));
  2615.  
  2616.   ptr_ftype_long
  2617.     = build_function_type (ptr_type_node, TYPE_ARG_TYPES (long_ftype_long));
  2618.  
  2619.   ptr_ftype_ptr_int_int_ptr
  2620.     = build_function_type (ptr_type_node,
  2621.                tree_cons (NULL_TREE, ptr_type_node,
  2622.                       tree_cons (NULL_TREE, integer_type_node,
  2623.                          tree_cons (NULL_TREE, integer_type_node,
  2624.                                 ptr_endlink))));
  2625.  
  2626.   void_ftype_ptr
  2627.     = build_function_type (void_type_node, ptr_endlink);
  2628.  
  2629.   void_ftype_ptr_int_int_ptr_int_int
  2630.     = build_function_type (void_type_node,
  2631.        tree_cons (NULL_TREE, ptr_type_node,
  2632.           tree_cons (NULL_TREE, integer_type_node,
  2633.          tree_cons (NULL_TREE, integer_type_node,
  2634.                 TYPE_ARG_TYPES (void_ftype_ptr_int_int)))));
  2635.  
  2636. #ifdef VTABLE_USES_MASK
  2637.   /* This is primarily for virtual function definition.  We
  2638.      declare an array of `void *', which can later be
  2639.      converted to the appropriate function pointer type.
  2640.      To do pointers to members, we need a mask which can
  2641.      distinguish an index value into a virtual function table
  2642.      from an address.  */
  2643.   vtbl_mask = build_int_2 (~(VINDEX_MAX - 1), -1);
  2644. #endif
  2645.  
  2646.   vtbl_type_node
  2647.     = build_array_type (ptr_type_node, NULL_TREE);
  2648.   layout_type (vtbl_type_node);
  2649.   vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0);
  2650.  
  2651.   builtin_function ("__builtin_alloca",
  2652.                     build_function_type (ptr_type_node, int_endlink),
  2653.                     BUILT_IN_ALLOCA);
  2654.  
  2655.   builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS);
  2656.   builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS);
  2657.   builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS);
  2658.   builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS);
  2659. #if 0
  2660.   /* Support for these has not been written in either expand_builtin
  2661.      or build_function_call.  */
  2662.   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV);
  2663.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV);
  2664.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR);
  2665.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL);
  2666.   builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD);
  2667.   builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM);
  2668.   builtin_function ("__builtin_memcpy", void_ftype_ptr_ptr_int, BUILT_IN_MEMCPY);
  2669.   builtin_function ("__builtin_memcmp", int_ftype_ptr_ptr_int, BUILT_IN_MEMCMP);
  2670.   builtin_function ("__builtin_memset", void_ftype_ptr_int_int, BUILT_IN_MEMSET);
  2671.   builtin_function ("__builtin_fsqrt", double_ftype_double, BUILT_IN_FSQRT);
  2672.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP);
  2673.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN);
  2674. #endif
  2675.  
  2676.   /* C++ extensions */
  2677.  
  2678.   unknown_type_node = make_node (UNKNOWN_TYPE);
  2679.   pushdecl (build_decl (TYPE_DECL,
  2680.             get_identifier ("unknown type"),
  2681.             unknown_type_node));
  2682.   TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
  2683.   TYPE_SIZE_UNIT (unknown_type_node) = TYPE_SIZE_UNIT (void_type_node);
  2684.   TYPE_ALIGN (unknown_type_node) = 1;
  2685.   TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
  2686.   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
  2687.   TREE_TYPE (unknown_type_node) = unknown_type_node;
  2688.   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result.  */
  2689.   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
  2690.   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
  2691.  
  2692.   /* Define these now, but use 0 as their DECL_FUNCTION_CODE.  This
  2693.      will install them in the global binding level, but cause them
  2694.      to be expanded normally.  */
  2695.   if (flag__main)
  2696.     {
  2697.       builtin_function ("__main", default_function_type, NOT_BUILT_IN);
  2698.       pushdecl (lookup_name (get_identifier ("__main")));
  2699.     }
  2700.   builtin_function ("__builtin_saveregs", default_function_type,
  2701.             BUILT_IN_SAVEREGS);
  2702.   builtin_function ("__builtin_classify_type", default_function_type,
  2703.             BUILT_IN_CLASSIFY_TYPE);
  2704.  
  2705.   {
  2706.     /* Simplify life by making a "vtable_entry_type".  Give its
  2707.        fields names so that the debugger can use them.  */
  2708.     tree fields[4];
  2709.     int i;
  2710.  
  2711.     vtable_entry_type = make_lang_type (RECORD_TYPE);
  2712.     CLASSTYPE_OFFSET (vtable_entry_type) = integer_zero_node;
  2713.     fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_DELTA_NAME), short_integer_type_node);
  2714.     fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_INDEX_NAME), short_integer_type_node);
  2715.     fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_PFN_NAME), ptr_type_node);
  2716.     TYPE_FIELDS (vtable_entry_type) = fields[0];
  2717.     for (i = 0; i < 2; i++)
  2718.       {
  2719.         DECL_FIELD_CONTEXT (fields[i]) = vtable_entry_type;
  2720.         TREE_CHAIN (fields[i]) = fields[i+1];
  2721.       }
  2722.     DECL_FIELD_CONTEXT (fields[i]) = vtable_entry_type;
  2723.     TYPE_ALIGN (vtable_entry_type) = TYPE_ALIGN (double_type_node);
  2724.     layout_type (vtable_entry_type);
  2725.     CLASSTYPE_VBASE_SIZE (vtable_entry_type) = integer_zero_node;
  2726.     TYPE_NAME (vtable_entry_type) = build_decl (TYPE_DECL,
  2727.                         get_identifier (VTBL_PTR_TYPE),
  2728.                         vtable_entry_type);
  2729.     layout_decl (TYPE_NAME (vtable_entry_type));
  2730.  
  2731.     /* Make this part of an invisible union.  */
  2732.     fields[3] = copy_node (fields[2]);
  2733.     TREE_TYPE (fields[3]) = short_integer_type_node;
  2734.     DECL_NAME (fields[3]) = get_identifier (VTABLE_DELTA2_NAME);
  2735.     DECL_MODE (fields[3]) = TYPE_MODE (short_integer_type_node);
  2736.     DECL_SIZE (fields[3]) = TYPE_SIZE (short_integer_type_node);
  2737.     DECL_SIZE_UNIT (fields[3]) = TYPE_SIZE_UNIT (short_integer_type_node);
  2738.     TREE_UNSIGNED (fields[3]) = 0;
  2739.     TREE_CHAIN (fields[2]) = fields[3];
  2740.  
  2741.     vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
  2742.   }
  2743.  
  2744. #ifdef SOS
  2745.   if (flag_all_virtual == 2)
  2746.     {
  2747.       tree fields[5];
  2748.       tree ptr_ftype_default
  2749.         = build_function_type (ptr_type_node, NULL_TREE);
  2750.       int i;
  2751.  
  2752.       builtin_function ("sosFindCode", ptr_ftype_default, NOT_BUILT_IN);
  2753.       builtin_function ("sosLookup", ptr_ftype_default, NOT_BUILT_IN);
  2754.       builtin_function ("sosImport", ptr_ftype_default, NOT_BUILT_IN);
  2755.       builtin_function ("sosDynError", ptr_ftype_default, NOT_BUILT_IN);
  2756.  
  2757.       zlink_type = make_lang_type (RECORD_TYPE);
  2758.       CLASSTYPE_OFFSET (zlink_type) = integer_zero_node;
  2759.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), string_type_node);
  2760.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("t"), char_type_node);
  2761.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), TYPE_POINTER_TO (default_function_type));
  2762.  
  2763.       TYPE_FIELDS (zlink_type) = fields[0];
  2764.       for (i = 0; i < 2; i++)
  2765.         {
  2766.       DECL_FIELD_CONTEXT (fields[i]) = zlink_type;
  2767.       TREE_CHAIN (fields[i]) = fields[i+1];
  2768.         }
  2769.       DECL_FIELD_CONTEXT (fields[i]) = zlink_type;
  2770.       TYPE_ALIGN (zlink_type) = 1;
  2771.       layout_type (zlink_type);
  2772.       CLASSTYPE_VBASE_SIZE (zlink_type) = integer_zero_node;
  2773.  
  2774.       zret_type = make_lang_type (RECORD_TYPE);
  2775.       CLASSTYPE_OFFSET (zret_type) = integer_zero_node;
  2776.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("cn"), string_type_node);
  2777.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), build_pointer_type (TYPE_POINTER_TO (default_function_type)));
  2778.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), integer_type_node);
  2779.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("bcl"), string_type_node);
  2780.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("f"), char_type_node);
  2781.  
  2782.       TYPE_FIELDS (zret_type) = fields[0];
  2783.       for (i = 0; i < 4; i++)
  2784.         {
  2785.       TREE_CHAIN (fields[i]) = fields[i+1];
  2786.       DECL_FIELD_CONTEXT (fields[i]) = zret_type;
  2787.         }
  2788.       DECL_FIELD_CONTEXT (fields[i]) = zret_type;
  2789.       TYPE_ALIGN (zret_type) = 1;
  2790.       layout_type (zret_type);
  2791.       CLASSTYPE_VBASE_SIZE (zret_type) = integer_zero_node;
  2792.     }
  2793. #endif
  2794.  
  2795.   /* Now, C++.  */
  2796.   current_lang_name = lang_name_cplusplus;
  2797.  
  2798.   auto_function ("__builtin_new", ptr_ftype_long, NOT_BUILT_IN);
  2799.   auto_function ("__builtin_vec_new", ptr_ftype_ptr_int_int_ptr, NOT_BUILT_IN);
  2800.   auto_function ("__builtin_delete", void_ftype_ptr, NOT_BUILT_IN);
  2801.   auto_function ("__builtin_vec_delete", void_ftype_ptr_int_int_ptr_int_int, NOT_BUILT_IN);
  2802.  
  2803.   abort_fndecl
  2804.     = define_function ("abort",
  2805.                build_function_type (void_type_node, void_list_node),
  2806.                NOT_BUILT_IN, 0);
  2807.  
  2808.   unhandled_exception_fndecl
  2809.     = define_function ("__unhandled_exception",
  2810.                build_function_type (void_type_node, NULL_TREE),
  2811.                NOT_BUILT_IN, 0);
  2812.  
  2813.   /* Perform other language dependent initializations.  */
  2814.   init_class_processing ();
  2815.   init_init_processing ();
  2816.   init_search_processing ();
  2817.   if (flag_handle_exceptions)
  2818.     {
  2819.       init_exception_processing ();
  2820.       if (flag_handle_exceptions == 2)
  2821.     /* Too much trouble to inline all the trys needed for this.  */
  2822.     flag_this_is_variable = 2;
  2823.     }
  2824.   if (flag_no_inline)
  2825.     flag_inline_functions = 0;
  2826. }
  2827.  
  2828. /* Make a definition for a builtin function named NAME and whose data type
  2829.    is TYPE.  TYPE should be a function type with argument types.
  2830.    FUNCTION_CODE tells later passes how to compile calls to this function.
  2831.    See tree.h for its possible values.  */
  2832.  
  2833. tree
  2834. define_function (name, type, function_code, pfn)
  2835.      char *name;
  2836.      tree type;
  2837.      enum built_in_function function_code;
  2838.      void (*pfn)();
  2839. {
  2840.   tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
  2841.   TREE_EXTERNAL (decl) = 1;
  2842.   TREE_PUBLIC (decl) = 1;
  2843.   make_function_rtl (decl);
  2844.   if (pfn) pfn (decl);
  2845.   DECL_SET_FUNCTION_CODE (decl, function_code);
  2846.   return decl;
  2847. }
  2848.  
  2849. /* Called when a declaration is seen that contains no names to declare.
  2850.    If its type is a reference to a structure, union or enum inherited
  2851.    from a containing scope, shadow that tag name for the current scope
  2852.    with a forward reference.
  2853.    If its type defines a new named structure or union
  2854.    or defines an enum, it is valid but we need not do anything here.
  2855.    Otherwise, it is an error.
  2856.  
  2857.    C++: may have to grok the declspecs to learn about static,
  2858.    complain for anonymous unions.  */
  2859.  
  2860. void
  2861. shadow_tag (declspecs)
  2862.      tree declspecs;
  2863. {
  2864.   int found_tag = 0;
  2865.   int warned = 0;
  2866.   register tree link;
  2867.   register enum tree_code code, ok_code = ERROR_MARK;
  2868.   register tree t = NULL_TREE;
  2869.  
  2870.   for (link = declspecs; link; link = TREE_CHAIN (link))
  2871.     {
  2872.       register tree value = TREE_VALUE (link);
  2873.  
  2874.       code = TREE_CODE (value);
  2875.       if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
  2876.     /* Used to test also that TYPE_SIZE (value) != 0.
  2877.        That caused warning for `struct foo;' at top level in the file.  */
  2878.     {
  2879.       register tree name = TYPE_NAME (value);
  2880.  
  2881.       if (name == NULL_TREE)
  2882.         name = lookup_tag_reverse (value, NULL_TREE);
  2883.  
  2884.       if (name && TREE_CODE (name) == TYPE_DECL)
  2885.         name = DECL_NAME (name);
  2886.  
  2887.       if (class_binding_level)
  2888.         t = lookup_tag (code, name, class_binding_level, 1);
  2889.       else
  2890.         t = lookup_tag (code, name, current_binding_level, 1);
  2891.  
  2892.       if (t == 0)
  2893.         {
  2894.           int temp = allocation_temporary_p ();
  2895.           if (temp)
  2896.         end_temporary_allocation ();
  2897.           if (IS_AGGR_TYPE_CODE (code))
  2898.         t = make_lang_type (code);
  2899.           else
  2900.         t = make_node (code);
  2901.           pushtag (name, t);
  2902.           if (temp)
  2903.         resume_temporary_allocation ();
  2904.           ok_code = code;
  2905.           break;
  2906.         }
  2907.       else if (name != 0 || code == ENUMERAL_TYPE)
  2908.         ok_code = code;
  2909.  
  2910.       if (ok_code != ERROR_MARK)
  2911.         found_tag++;
  2912.       else
  2913.         {
  2914.           if (!warned)
  2915.         warning ("useless keyword or type name in declaration");
  2916.           warned = 1;
  2917.         }
  2918.     }
  2919.     }
  2920.  
  2921.   /* This is where the variables in an anonymous union are
  2922.      declared.  An anonymous union declaration looks like:
  2923.      union { ... } ;
  2924.      because there is no declarator after the union, the parser
  2925.      sends that declaration here.  */
  2926.   if (ok_code == UNION_TYPE
  2927.       && t != NULL_TREE
  2928.       && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
  2929.        && ANON_AGGRNAME_P (TYPE_NAME (t)))
  2930.       || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
  2931.           && ANON_AGGRNAME_P (DECL_NAME (TYPE_NAME (t)))))
  2932.       && TYPE_FIELDS (t))
  2933.     {
  2934.       tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE);
  2935.       finish_anon_union (decl);
  2936.     }
  2937.   else if (ok_code == RECORD_TYPE
  2938.        && found_tag == 1
  2939.        && TYPE_LANG_SPECIFIC (t)
  2940.        && CLASSTYPE_DECLARED_EXCEPTION (t))
  2941.     {
  2942.       if (TYPE_SIZE (t))
  2943.     error_with_aggr_type (t, "redeclaration of exception `%s'");
  2944.       else
  2945.     {
  2946.       tree ename, decl;
  2947.       int temp = allocation_temporary_p ();
  2948.       int momentary = suspend_momentary ();
  2949.       if (temp)
  2950.         end_temporary_allocation ();
  2951.  
  2952.       pushclass (t, 0);
  2953.       finish_exception (t, NULL_TREE);
  2954.  
  2955.       ename = TYPE_NAME (t);
  2956.       if (TREE_CODE (ename) == TYPE_DECL)
  2957.         ename = DECL_NAME (ename);
  2958.       decl = build_lang_field_decl (VAR_DECL, ename, t);
  2959.       finish_exception_decl (current_class_name, decl);
  2960.       end_exception_decls ();
  2961.  
  2962.       if (temp)
  2963.         resume_temporary_allocation ();
  2964.       if (momentary)
  2965.         resume_momentary ();
  2966.     }
  2967.     }
  2968.   else if (!warned)
  2969.     {
  2970.       if (found_tag > 1)
  2971.     warning ("multiple types in one declaration");
  2972.       if (found_tag == 0)
  2973.     warning ("empty declaration");
  2974.     }
  2975. }
  2976.  
  2977. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  2978.  
  2979. tree
  2980. groktypename (typename)
  2981.      tree typename;
  2982. {
  2983.   if (TREE_CODE (typename) != TREE_LIST)
  2984.     return typename;
  2985.   return grokdeclarator (TREE_VALUE (typename),
  2986.              TREE_PURPOSE (typename),
  2987.              TYPENAME, 0, NULL_TREE);
  2988. }
  2989.  
  2990. /* Decode a declarator in an ordinary declaration or data definition.
  2991.    This is called as soon as the type information and variable name
  2992.    have been parsed, before parsing the initializer if any.
  2993.    Here we create the ..._DECL node, fill in its type,
  2994.    and put it on the list of decls for the current context.
  2995.    The ..._DECL node is returned as the value.
  2996.  
  2997.    Exception: for arrays where the length is not specified,
  2998.    the type is left null, to be filled in by `finish_decl'.
  2999.  
  3000.    Function definitions do not come here; they go to start_function
  3001.    instead.  However, external and forward declarations of functions
  3002.    do go through here.  Structure field declarations are done by
  3003.    grokfield and not through here.  */
  3004.  
  3005. /* Set this to zero to debug not using the temporary obstack
  3006.    to parse initializers.  */
  3007. int debug_temp_inits = 1;
  3008.  
  3009. tree
  3010. start_decl (declarator, declspecs, initialized, raises)
  3011.      tree declspecs, declarator;
  3012.      int initialized;
  3013.      tree raises;
  3014. {
  3015.   register tree decl = grokdeclarator (declarator, declspecs,
  3016.                        NORMAL, initialized, raises);
  3017.   register tree type, tem;
  3018.   int init_written = initialized;
  3019.  
  3020.   if (decl == NULL_TREE) return decl;
  3021.  
  3022.   type = TREE_TYPE (decl);
  3023.  
  3024.   /* Don't lose if destructors must be executed at file-level.  */
  3025.   if (TREE_STATIC (decl)
  3026.       && TYPE_NEEDS_DESTRUCTOR (type)
  3027.       && TREE_PERMANENT (decl) == 0)
  3028.     {
  3029.       end_temporary_allocation ();
  3030.       decl = copy_node (decl);
  3031.       if (TREE_CODE (type) == ARRAY_TYPE)
  3032.     {
  3033.       tree itype = TYPE_DOMAIN (type);
  3034.       if (itype && ! TREE_PERMANENT (itype))
  3035.         {
  3036.           itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
  3037.           type = build_cplus_array_type (TREE_TYPE (type), itype);
  3038.           TREE_TYPE (decl) = type;
  3039.         }
  3040.     }
  3041.       resume_temporary_allocation ();
  3042.     }
  3043.  
  3044.   /* Interesting work for this is done in `finish_exception_decl'.  */
  3045.   if (TREE_CODE (type) == RECORD_TYPE
  3046.       && CLASSTYPE_DECLARED_EXCEPTION (type))
  3047.     return decl;
  3048.  
  3049.   if (DECL_CONTEXT (decl))
  3050.     {
  3051.       /* If it was not explicitly declared `extern',
  3052.      revoke any previous claims of TREE_EXTERNAL.  */
  3053.       if (DECL_EXTERNAL (decl) == 0)
  3054.     TREE_EXTERNAL (decl) = 0;
  3055.       if (DECL_LANG_SPECIFIC (decl))
  3056.     DECL_IN_AGGR_P (decl) = 0;
  3057.       pushclass (DECL_CONTEXT (decl), 2);
  3058.     }
  3059.  
  3060.   /* If this type of object needs a cleanup, and control may
  3061.      jump past it, make a new binding level so that it is cleaned
  3062.      up only when it is initialized first.  */
  3063.   if (TYPE_NEEDS_DESTRUCTOR (type)
  3064.       && current_binding_level->more_cleanups_ok == 0)
  3065.     pushlevel_temporary (1);
  3066.  
  3067.   if (initialized)
  3068.     /* Is it valid for this decl to have an initializer at all?
  3069.        If not, set INITIALIZED to zero, which will indirectly
  3070.        tell `finish_decl' to ignore the initializer once it is parsed.  */
  3071.     switch (TREE_CODE (decl))
  3072.       {
  3073.       case TYPE_DECL:
  3074.     /* typedef foo = bar  means give foo the same type as bar.
  3075.        We haven't parsed bar yet, so `finish_decl' will fix that up.
  3076.        Any other case of an initialization in a TYPE_DECL is an error.  */
  3077.     if (pedantic || list_length (declspecs) > 1)
  3078.       {
  3079.         error ("typedef `%s' is initialized",
  3080.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3081.         initialized = 0;
  3082.       }
  3083.     break;
  3084.  
  3085.       case FUNCTION_DECL:
  3086.     error ("function `%s' is initialized like a variable",
  3087.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3088.     initialized = 0;
  3089.     break;
  3090.  
  3091.       default:
  3092.     /* Don't allow initializations for incomplete types
  3093.        except for arrays which might be completed by the initialization.  */
  3094.     if (TYPE_SIZE (type) != 0)
  3095.       ;                     /* A complete type is ok.  */
  3096.     else if (TREE_CODE (type) != ARRAY_TYPE)
  3097.       {
  3098.         error ("variable `%s' has initializer but incomplete type",
  3099.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3100.         initialized = 0;
  3101.       }
  3102.     else if (TYPE_SIZE (TREE_TYPE (type)) == 0)
  3103.       {
  3104.         error ("elements of array `%s' have incomplete type",
  3105.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3106.         initialized = 0;
  3107.       }
  3108.       }
  3109.  
  3110.   if (!initialized && TREE_CODE (decl) != TYPE_DECL
  3111.       && IS_AGGR_TYPE (type) && ! TREE_EXTERNAL (decl))
  3112.     {
  3113.       if (TYPE_SIZE (type) == 0)
  3114.     {
  3115.       error ("aggregate `%s' has incomplete type and cannot be initialized",
  3116.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  3117.       /* Change the type so that assemble_variable will give
  3118.          DECL an rtl we can live with: (mem (const_int 0)).  */
  3119.       TREE_TYPE (decl) = error_mark_node;
  3120.       type = error_mark_node;
  3121.     }
  3122.       else
  3123.     {
  3124.       /* If any base type in the hierarchy of TYPE needs a constructor,
  3125.          then we set initialized to 1.  This way any nodes which are
  3126.          created for the purposes of initializing this aggregate
  3127.          will live as long as it does.  This is necessary for global
  3128.          aggregates which do not have their initializers processed until
  3129.          the end of the file.  */
  3130.       initialized = TYPE_NEEDS_CONSTRUCTING (type);
  3131.     }
  3132.     }
  3133.  
  3134.   if (initialized)
  3135.     {
  3136.       if (current_binding_level != global_binding_level
  3137.       && TREE_EXTERNAL (decl))
  3138.     warning ("declaration of `%s' has `extern' and is initialized",
  3139.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  3140.       TREE_EXTERNAL (decl) = 0;
  3141.       if (current_binding_level == global_binding_level)
  3142.     TREE_STATIC (decl) = 1;
  3143.  
  3144.       /* Tell `pushdecl' this is an initialized decl
  3145.      even though we don't yet have the initializer expression.
  3146.      Also tell `finish_decl' it may store the real initializer.  */
  3147.       DECL_INITIAL (decl) = error_mark_node;
  3148.     }
  3149.  
  3150.   /* Add this decl to the current binding level, but not if it
  3151.      comes from another scope, e.g. a static member variable.
  3152.      TEM may equal DECL or it may be a previous decl of the same name.  */
  3153.   if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
  3154.       || TREE_CODE (type) == LANG_TYPE)
  3155.     tem = decl;
  3156.   else
  3157.     {
  3158.       tem = pushdecl (decl);
  3159.       if (TREE_CODE (tem) == TREE_LIST)
  3160.     {
  3161.       tree tem2 = value_member (decl, tem);
  3162.       if (tem2 != NULL_TREE)
  3163.         tem = TREE_VALUE (tem2);
  3164.       else
  3165.         {
  3166.           while (tem && ! decls_match (decl, TREE_VALUE (tem)))
  3167.         tem = TREE_CHAIN (tem);
  3168.           if (tem == NULL_TREE)
  3169.         tem = decl;
  3170.           else
  3171.         tem = TREE_VALUE (tem);
  3172.         }
  3173.     }
  3174.     }
  3175.  
  3176. #if 0
  3177.   /* We don't do this yet for GNU C++.  */
  3178.   /* For a local variable, define the RTL now.  */
  3179.   if (current_binding_level != global_binding_level
  3180.       /* But not if this is a duplicate decl
  3181.      and we preserved the rtl from the previous one
  3182.      (which may or may not happen).  */
  3183.       && DECL_RTL (tem) == 0)
  3184.     {
  3185.       if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
  3186.     expand_decl (tem);
  3187.       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  3188.            && DECL_INITIAL (tem) != 0)
  3189.     expand_decl (tem);
  3190.     }
  3191. #endif
  3192.  
  3193.   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl))
  3194.     /* @@ Also done in start_function.  */
  3195.     push_overloaded_decl (tem);
  3196.  
  3197.   if (init_written
  3198.       && ! (TREE_CODE (tem) == PARM_DECL
  3199.         || (TREE_READONLY (tem)
  3200.         && (TREE_CODE (tem) == VAR_DECL
  3201.             || TREE_CODE (tem) == FIELD_DECL))))
  3202.     {
  3203.       /* When parsing and digesting the initializer,
  3204.      use temporary storage.  Do this even if we will ignore the value.  */
  3205.       if (current_binding_level == global_binding_level && debug_temp_inits)
  3206.     {
  3207.       if (TYPE_NEEDS_CONSTRUCTING (type))
  3208.         /* In this case, the initializer must lay down in permanent
  3209.            storage, since it will be saved until `finish_file' is run.   */
  3210.         ;
  3211.       else
  3212.         temporary_allocation ();
  3213.     }
  3214.     }
  3215.  
  3216.   return tem;
  3217. }
  3218.  
  3219. static void
  3220. make_temporary_for_reference (decl, ctor_call, init, cleanupp)
  3221.      tree decl, ctor_call, init;
  3222.      tree *cleanupp;
  3223. {
  3224.   tree type = TREE_TYPE (decl);
  3225.   tree target_type = TREE_TYPE (type);
  3226.   tree tmp, tmp_addr;
  3227.  
  3228.   if (ctor_call)
  3229.     {
  3230.       tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
  3231.       if (TREE_CODE (tmp_addr) == NOP_EXPR)
  3232.     tmp_addr = TREE_OPERAND (tmp_addr, 0);
  3233.       assert (TREE_CODE (tmp_addr) == ADDR_EXPR);
  3234.       tmp = TREE_OPERAND (tmp_addr, 0);
  3235.     }
  3236.   else
  3237.     {
  3238.       tmp = get_temp_name (target_type,
  3239.                current_binding_level == global_binding_level);
  3240.       tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
  3241.     }
  3242.  
  3243.   TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
  3244.   DECL_INITIAL (decl) = convert_pointer_to (target_type, tmp_addr);
  3245.   TREE_TYPE (DECL_INITIAL (decl)) = type;
  3246.   if (TYPE_NEEDS_CONSTRUCTING (target_type))
  3247.     {
  3248.       if (current_binding_level == global_binding_level)
  3249.     {
  3250.       /* lay this variable out now.  Otherwise `output_addressed_constants'
  3251.          gets confused by its initializer.  */
  3252.       make_decl_rtl (tmp, 0, 1);
  3253.       static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
  3254.     }
  3255.       else
  3256.     {
  3257.       if (ctor_call != NULL_TREE)
  3258.         init = ctor_call;
  3259.       else
  3260.         init = build_method_call (tmp, DECL_NAME (TYPE_NAME (target_type)),
  3261.                       build_tree_list (NULL_TREE, init),
  3262.                       NULL_TREE, LOOKUP_NORMAL);
  3263.       DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
  3264.                        DECL_INITIAL (decl));
  3265.       *cleanupp = maybe_build_cleanup (tmp);
  3266.     }
  3267.     }
  3268.   else
  3269.     {
  3270.       DECL_INITIAL (tmp) = init;
  3271.       TREE_STATIC (tmp) = current_binding_level == global_binding_level;
  3272.       finish_decl (tmp, init, 0);
  3273.     }
  3274.   if (TREE_STATIC (tmp))
  3275.     preserve_initializer ();
  3276. }
  3277.  
  3278. /* Handle initialization of references.
  3279.    These three arguments from from `finish_decl', and have the
  3280.    same meaning here that they do there.  */
  3281. static void
  3282. grok_reference_init (decl, type, init, cleanupp)
  3283.      tree decl, type, init;
  3284.      tree *cleanupp;
  3285. {
  3286.   char *errstr = 0;
  3287.   int is_reference;
  3288.   tree tmp;
  3289.   tree this_ptr_type, actual_init;
  3290.  
  3291.   if (init == NULL_TREE)
  3292.     {
  3293.       if (DECL_LANG_SPECIFIC (decl) == 0 || DECL_IN_AGGR_P (decl) == 0)
  3294.     {
  3295.       error ("variable declared as reference not initialized");
  3296.       if (TREE_CODE (decl) == VAR_DECL)
  3297.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  3298.     }
  3299.       return;
  3300.     }
  3301.  
  3302.   if (TREE_CODE (init) == TREE_LIST)
  3303.     init = build_compound_expr (init);
  3304.   is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE;
  3305.   tmp = is_reference ? convert_from_reference (init) : init;
  3306.  
  3307.   if (is_reference)
  3308.     {
  3309.       if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  3310.                TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0))
  3311.     errstr = "initialization of `%s' from dissimilar reference type";
  3312.       else if (TREE_READONLY (TREE_TYPE (type))
  3313.            >= TREE_READONLY (TREE_TYPE (TREE_TYPE (init))))
  3314.     {
  3315.       is_reference = 0;
  3316.       init = tmp;
  3317.     }
  3318.     }
  3319.   else
  3320.     {
  3321.       if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
  3322.       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
  3323.     {
  3324.       /* Note: default conversion is only called in very
  3325.          special cases.  */
  3326.       init = default_conversion (init);
  3327.     }
  3328.       if (IS_AGGR_TYPE (TREE_TYPE (type))
  3329.       && IS_AGGR_TYPE (TREE_TYPE (init))
  3330.       && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  3331.             TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0))
  3332.     {
  3333.       /* Nothing happens.  */
  3334.     }
  3335.       else if (TREE_CODE (TREE_TYPE (type)) == TREE_CODE (TREE_TYPE (init)))
  3336.     {
  3337.       init = convert (TREE_TYPE (type), init);
  3338.     }
  3339.       else if (init != error_mark_node
  3340.            && ! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  3341.                    TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0))
  3342.     errstr = "invalid type conversion for reference";
  3343.     }
  3344.  
  3345.   if (errstr)
  3346.     {
  3347.       /* Things did not go smoothly; look for operator& type conversion.  */
  3348.       if (IS_AGGR_TYPE (TREE_TYPE (tmp)))
  3349.     {
  3350.       tmp = build_type_conversion (CONVERT_EXPR, type, init, 0);
  3351.       if (tmp != NULL_TREE)
  3352.         {
  3353.           init = tmp;
  3354.           if (tmp == error_mark_node)
  3355.         errstr = "ambiguous pointer conversion";
  3356.           else
  3357.         errstr = 0;
  3358.           is_reference = 1;
  3359.         }
  3360.       else
  3361.         {
  3362.           tmp = build_type_conversion (CONVERT_EXPR, TREE_TYPE (type), init, 0);
  3363.           if (tmp != NULL_TREE)
  3364.         {
  3365.           init = tmp;
  3366.           if (tmp == error_mark_node)
  3367.             errstr = "ambiguous pointer conversion";
  3368.           else
  3369.             errstr = 0;
  3370.           is_reference = 0;
  3371.         }
  3372.         }
  3373.     }
  3374.       /* Look for constructor.  */
  3375.       else if (IS_AGGR_TYPE (TREE_TYPE (type))
  3376.            && TYPE_HAS_CONSTRUCTOR (TREE_TYPE (type)))
  3377.     {
  3378.       tmp = get_temp_name (TREE_TYPE (type),
  3379.                    current_binding_level == global_binding_level);
  3380.       tmp = build_method_call (tmp, DECL_NAME (TYPE_NAME (TREE_TYPE (type))),
  3381.                    build_tree_list (NULL_TREE, init),
  3382.                    NULL_TREE, LOOKUP_NORMAL);
  3383.       if (tmp == NULL_TREE || tmp == error_mark_node)
  3384.         {
  3385.           if (TREE_CODE (decl) == VAR_DECL)
  3386.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  3387.           error_with_decl (decl, "constructor failed to build reference initializer");
  3388.           return;
  3389.         }
  3390.       make_temporary_for_reference (decl, tmp, init, cleanupp);
  3391.       goto done;
  3392.     }
  3393.     }
  3394.  
  3395.   if (errstr)
  3396.     {
  3397.       error_with_decl (decl, errstr);
  3398.       if (TREE_CODE (decl) == VAR_DECL)
  3399.     SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  3400.       return;
  3401.     }
  3402.  
  3403.   /* In the case of initialization, it is permissable
  3404.      to assign one reference to another.  */
  3405.   this_ptr_type = build_pointer_type (TREE_TYPE (type));
  3406.  
  3407.   if (is_reference)
  3408.     {
  3409.       if (TREE_VOLATILE (init))
  3410.     DECL_INITIAL (decl) = save_expr (init);
  3411.       else
  3412.     DECL_INITIAL (decl) = init;
  3413.     }
  3414.   else if (lvalue_p (init))
  3415.     {
  3416.       tmp = build_unary_op (ADDR_EXPR, init, 0);
  3417.       if (TREE_CODE (tmp) == ADDR_EXPR
  3418.       && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR)
  3419.     {
  3420.       /* Associate the cleanup with the reference so that we
  3421.          don't get burned by "aggressive" cleanup policy.  */
  3422.       *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2);
  3423.       TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node;
  3424.     }
  3425.       DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp);
  3426.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  3427.       if (DECL_INITIAL (decl) == current_class_decl)
  3428.     DECL_INITIAL (decl) = copy_node (current_class_decl);
  3429.       TREE_TYPE (DECL_INITIAL (decl)) = type;
  3430.     }
  3431.   else if ((actual_init = unary_complex_lvalue (ADDR_EXPR, init)))
  3432.     {
  3433.       /* The initializer for this decl goes into its
  3434.      DECL_REFERENCE_SLOT.  Make sure that we can handle
  3435.      multiple evaluations without ill effect.  */
  3436.       if (TREE_CODE (actual_init) == ADDR_EXPR
  3437.       && TREE_CODE (TREE_OPERAND (actual_init, 0)) == NEW_EXPR)
  3438.     actual_init = save_expr (actual_init);
  3439.       DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init);
  3440.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  3441.       TREE_TYPE (DECL_INITIAL (decl)) = type;
  3442.     }
  3443.   else if (TREE_READONLY (TREE_TYPE (type)))
  3444.     /* Section 8.4.3 allows us to make a temporary for
  3445.        the initialization of const&.  */
  3446.     make_temporary_for_reference (decl, NULL_TREE, init, cleanupp);
  3447.   else
  3448.     {
  3449.       error_with_decl (decl, "type mismatch in initialization of `%s' (use `const')");
  3450.       DECL_INITIAL (decl) = error_mark_node;
  3451.     }
  3452.  
  3453.  done:
  3454.   /* ?? Can this be optimized in some cases to
  3455.      hand back the DECL_INITIAL slot??  */
  3456.   if (TYPE_SIZE (TREE_TYPE (type)))
  3457.     SET_DECL_REFERENCE_SLOT (decl, convert_from_reference (decl));
  3458.  
  3459.   if (TREE_STATIC (decl) && ! TREE_LITERAL (DECL_INITIAL (decl)))
  3460.     {
  3461.       expand_static_init (decl, DECL_INITIAL (decl));
  3462.       DECL_INITIAL (decl) = 0;
  3463.     }
  3464. }
  3465.  
  3466. /* Finish processing of a declaration;
  3467.    install its line number and initial value.
  3468.    If the length of an array type is not known before,
  3469.    it must be determined now, from the initial value, or it is an error.
  3470.  
  3471.    For C++, `finish_decl' must be fairly evasive:  it must keep initializers
  3472.    for aggregates that have constructors alive on the permanent obstack,
  3473.    so that the global initializing functions can be written at the end.
  3474.  
  3475.    INIT0 holds the value of an initializer that should be allowed to escape
  3476.    the normal rules.
  3477.  
  3478.    For functions that take defualt parameters, DECL points to its
  3479.    "maximal" instantiation.  finish_decl must then also declared its
  3480.    subsequently lower and lower forms of instantiation, checking for
  3481.    ambiguity as it goes.  This can be sped up later.  */
  3482.  
  3483. void
  3484. finish_decl (decl, init, asmspec_tree)
  3485.      tree decl, init;
  3486.      tree asmspec_tree;
  3487. {
  3488.   register tree type;
  3489.   tree cleanup = NULL_TREE, ttype;
  3490.   int was_incomplete;
  3491.   int temporary = allocation_temporary_p ();
  3492.   char *asmspec = 0;
  3493.   int was_readonly = 0;
  3494.  
  3495.   /* If this is 0, then we did not change obstacks.  */
  3496.   if (! decl)
  3497.     {
  3498.       if (init)
  3499.     error ("assignment (not initialization) in declaration");
  3500.       return;
  3501.     }
  3502.  
  3503.   if (asmspec_tree)
  3504.     {
  3505.       asmspec = TREE_STRING_POINTER (asmspec_tree);
  3506.       /* Zero out old RTL, since we will rewrite it.  */
  3507.       DECL_RTL (decl) = 0;
  3508.     }
  3509.  
  3510.   /* If the type of the thing we are declaring either has
  3511.      a constructor, or has a virtual function table pointer,
  3512.      AND its initialization was accepted by `start_decl',
  3513.      then we stayed on the permanent obstack through the
  3514.      declaration, otherwise, changed obstacks as GCC would.  */
  3515.  
  3516.   type = TREE_TYPE (decl);
  3517.  
  3518.   was_incomplete = (DECL_SIZE (decl) == 0);
  3519.  
  3520.   /* Take care of TYPE_DECLs up front.  */
  3521.   if (TREE_CODE (decl) == TYPE_DECL)
  3522.     {
  3523.       if (init && DECL_INITIAL (decl))
  3524.     {
  3525.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  3526.       TREE_TYPE (decl) = type = TREE_TYPE (init);
  3527.       DECL_INITIAL (decl) = init = 0;
  3528.     }
  3529.       if (IS_AGGR_TYPE (type))
  3530.     {
  3531. #ifndef BREAK_C_TAGS
  3532.       if (current_lang_name == lang_name_cplusplus)
  3533. #endif
  3534.         {
  3535.           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
  3536.         warning ("shadowing previous type declaration of `%s'",
  3537.              IDENTIFIER_POINTER (DECL_NAME (decl)));
  3538.           TREE_TYPE (DECL_NAME (decl)) = decl;
  3539.         }
  3540.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  3541.     }
  3542.  
  3543. #ifdef FIELD_XREF
  3544.       FIELD_xref_decl(current_function_decl,decl);
  3545. #endif
  3546.  
  3547.       rest_of_decl_compilation (decl, 0,
  3548.                 current_binding_level == global_binding_level, 0);
  3549.       goto finish_end;
  3550.     }
  3551.   if (IS_AGGR_TYPE (type) && CLASSTYPE_DECLARED_EXCEPTION (type))
  3552.     {
  3553.       finish_exception_decl (NULL_TREE, decl);
  3554.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  3555.       goto finish_end;
  3556.     }
  3557.   if (TREE_CODE (decl) != FUNCTION_DECL)
  3558.     {
  3559.       ttype = target_type (type);
  3560.       if (TYPE_NAME (ttype)
  3561.       && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
  3562.       && ANON_AGGRNAME_P (DECL_NAME (TYPE_NAME (ttype))))
  3563.     {
  3564.       tree old_id = DECL_NAME (TYPE_NAME (ttype));
  3565.       char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
  3566.       newname[0] = '_';
  3567.       bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
  3568.          IDENTIFIER_LENGTH (old_id) + 1);
  3569.       old_id = get_identifier (newname);
  3570.       lookup_tag_reverse (ttype, old_id);
  3571.       DECL_NAME (TYPE_NAME (ttype)) = old_id;
  3572.     }
  3573.     }
  3574.  
  3575.   if (! TREE_EXTERNAL (decl) && TREE_READONLY (decl)
  3576.       && TYPE_NEEDS_CONSTRUCTING (type))
  3577.     {
  3578.  
  3579.       /* Currently, GNU C++ puts constants in text space, making them
  3580.      impossible to initialize.  In the future, one would hope for
  3581.      an operating system which understood the difference between
  3582.      initialization and the running of a program.  */
  3583.       was_readonly = 1;
  3584.       TREE_READONLY (decl) = 0;
  3585.     }
  3586.  
  3587.   if (TREE_CODE (decl) == FIELD_DECL)
  3588.     {
  3589.       if (init && init != error_mark_node)
  3590.     assert (TREE_PERMANENT (init));
  3591.  
  3592.       if (asmspec)
  3593.     {
  3594.       /* This must override the asm specifier which was placed
  3595.          by grokclassfn.  Lay this out fresh.
  3596.          
  3597.          @@ Should emit an error if this redefines an asm-specified
  3598.          @@ name, or if we have already used the function's name.  */
  3599.       DECL_RTL (TREE_TYPE (decl)) = 0;
  3600.       DECL_ASSEMBLER_NAME (decl) = asmspec;
  3601.       make_decl_rtl (decl, asmspec, 0);
  3602.     }
  3603.     }
  3604.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  3605.   else if (init != 0 && DECL_INITIAL (decl) == 0)
  3606.     init = 0;
  3607.   else if (TREE_EXTERNAL (decl))
  3608.     ;
  3609.   else if (TREE_CODE (type) == REFERENCE_TYPE)
  3610.     {
  3611.       grok_reference_init (decl, type, init, &cleanup);
  3612.       init = 0;
  3613.     }
  3614.  
  3615. #ifdef FIELD_XREF
  3616.   FIELD_xref_decl(current_function_decl,decl);
  3617. #endif
  3618.  
  3619.   if (TREE_CODE (decl) == FIELD_DECL || TREE_EXTERNAL (decl))
  3620.     ;
  3621.   else if (TREE_CODE (decl) == CONST_DECL)
  3622.     {
  3623.       assert (TREE_CODE (decl) != REFERENCE_TYPE);
  3624.  
  3625.       DECL_INITIAL (decl) = init;
  3626.  
  3627.       /* This will keep us from needing to worry about our obstacks.  */
  3628.       assert (init != 0);
  3629.       init = 0;
  3630.     }
  3631.   else if (init)
  3632.     {
  3633.       if (TYPE_NEEDS_CONSTRUCTING (type))
  3634.     {
  3635.       if (TREE_CODE (type) == ARRAY_TYPE)
  3636.         init = digest_init (type, init, 0);
  3637.       else if (TREE_CODE (init) == CONSTRUCTOR
  3638.            && CONSTRUCTOR_ELTS (init) != NULL_TREE)
  3639.         {
  3640.           error_with_decl (decl, "`%s' must be initialized by constructor, not by `{...}'");
  3641.           init = error_mark_node;
  3642.         }
  3643. #if 0
  3644.       /* fix this in `build_functional_cast' instead.
  3645.          Here's the trigger code:
  3646.  
  3647.         struct ostream
  3648.         {
  3649.           ostream ();
  3650.           ostream (int, char *);
  3651.           ostream (char *);
  3652.           operator char *();
  3653.           ostream (void *);
  3654.           operator void *();
  3655.           operator << (int);
  3656.         };
  3657.         int buf_size = 1024;
  3658.         static char buf[buf_size];
  3659.         const char *debug(int i) {
  3660.           char *b = &buf[0];
  3661.           ostream o = ostream(buf_size, b);
  3662.           o << i;
  3663.           return buf;
  3664.         }
  3665.         */
  3666.  
  3667.       else if (TREE_CODE (init) == NEW_EXPR
  3668.            && TREE_CODE (TREE_OPERAND (init, 1) == CPLUS_NEW_EXPR))
  3669.         {
  3670.           /* User wrote something like `foo x = foo (args)'  */
  3671.           assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL);
  3672.           assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE);
  3673.  
  3674.           /* User wrote exactly `foo x = foo (args)'  */
  3675.           if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
  3676.         {
  3677.           init = build (CALL_EXPR, TREE_TYPE (init),
  3678.                 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
  3679.                 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
  3680.           TREE_VOLATILE (init) = 1;
  3681.         }
  3682.         }
  3683. #endif
  3684.  
  3685.       /* We must hide the initializer so that expand_decl
  3686.          won't try to do something it does not understand.  */
  3687.       if (current_binding_level == global_binding_level)
  3688.         {
  3689.           tree value = digest_init (type, empty_init_node, 0);
  3690.           DECL_INITIAL (decl) = value;
  3691.         }
  3692.       else
  3693.         DECL_INITIAL (decl) = error_mark_node;
  3694.     }
  3695.       else
  3696.     {
  3697.       if (TREE_CODE (init) != TREE_VEC)
  3698.         init = store_init_value (decl, init);
  3699.  
  3700.       if (init)
  3701.         /* Don't let anyone try to initialize this variable
  3702.            until we are ready to do so.  */
  3703.         DECL_INITIAL (decl) = error_mark_node;
  3704.     }
  3705.     }
  3706.   else if (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))
  3707.     {
  3708.       tree ctype = type;
  3709.       while (TREE_CODE (ctype) == ARRAY_TYPE)
  3710.     ctype = TREE_TYPE (ctype);
  3711.       if (! TYPE_NEEDS_CONSTRUCTOR (ctype))
  3712.     {
  3713.       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
  3714.         error_with_decl (decl, "structure `%s' with uninitialized const members");
  3715.       if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
  3716.         error_with_decl (decl, "structure `%s' with uninitialized reference members");
  3717.     }
  3718.  
  3719.       if (TREE_CODE (decl) == VAR_DECL
  3720.       && !TYPE_NEEDS_CONSTRUCTING (type)
  3721.       && (TREE_READONLY (type) || TREE_READONLY (decl)))
  3722.     error_with_decl (decl, "uninitialized const `%s'");
  3723.  
  3724.       /* Initialize variables in need of static initialization
  3725.      with `empty_init_node' to keep assemble_variable from putting them
  3726.      in the wrong program space.  */
  3727.       if (TREE_STATIC (decl)
  3728.       && TREE_CODE (decl) == VAR_DECL
  3729.       && TYPE_NEEDS_CONSTRUCTING (type)
  3730.       && (DECL_INITIAL (decl) == 0
  3731.           || DECL_INITIAL (decl) == error_mark_node))
  3732.     {
  3733.       tree value = digest_init (type, empty_init_node, 0);
  3734.       DECL_INITIAL (decl) = value;
  3735.     }
  3736.     }
  3737.   else if (TREE_CODE (decl) == VAR_DECL
  3738.        && TREE_CODE (type) != REFERENCE_TYPE
  3739.        && (TREE_READONLY (type) || TREE_READONLY (decl)))
  3740.     {
  3741.       if (! TREE_STATIC (decl))
  3742.     error_with_decl (decl, "uninitialized const `%s'");
  3743.     }
  3744.  
  3745.   /* For top-level declaration, the initial value was read in
  3746.      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
  3747.      must go in the permanent obstack; but don't discard the
  3748.      temporary data yet.  */
  3749.  
  3750.   if (current_binding_level == global_binding_level && temporary)
  3751.     end_temporary_allocation ();
  3752.  
  3753.   /* Deduce size of array from initialization, if not already known.  */
  3754.  
  3755.   if (TREE_CODE (type) == ARRAY_TYPE
  3756.       && TYPE_DOMAIN (type) == 0
  3757.       && TREE_CODE (decl) != TYPE_DECL)
  3758.     {
  3759.       int do_default = ! ((!pedantic && TREE_STATIC (decl))
  3760.               || TREE_EXTERNAL (decl));
  3761.       tree initializer = init ? init : DECL_INITIAL (decl);
  3762.       int failure = complete_array_type (type, initializer, do_default);
  3763.  
  3764.       if (failure == 1)
  3765.     error_with_decl (decl, "initializer fails to determine size of `%s'");
  3766.  
  3767.       if (failure == 2)
  3768.     {
  3769.       if (do_default)
  3770.         error_with_decl (decl, "array size missing in `%s'");
  3771.       else if (!pedantic && TREE_STATIC (decl))
  3772.         TREE_EXTERNAL (decl) = 1;
  3773.     }
  3774.  
  3775.       if (pedantic && TYPE_DOMAIN (type) != 0
  3776.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  3777.                   integer_zero_node))
  3778.     error_with_decl (decl, "zero-size array `%s'");
  3779.  
  3780.       layout_decl (decl, 0);
  3781.     }
  3782.  
  3783.   if (TREE_CODE (decl) == VAR_DECL)
  3784.     {
  3785.       if (TREE_STATIC (decl) && DECL_SIZE (decl) == 0)
  3786.     {
  3787.       /* A static variable with an incomplete type:
  3788.          that is an error if it is initialized or `static'.
  3789.          Otherwise, let it through, but if it is not `extern'
  3790.          then it may cause an error message later.  */
  3791.       if (! (TREE_PUBLIC (decl) && DECL_INITIAL (decl) == 0))
  3792.         error_with_decl (decl, "storage size of `%s' isn't known");
  3793.       init = 0;
  3794.     }
  3795.       else if (!TREE_EXTERNAL (decl) && DECL_SIZE (decl) == 0)
  3796.     {
  3797.       /* An automatic variable with an incomplete type:
  3798.          that is an error.  */
  3799.       error_with_decl (decl, "storage size of `%s' isn't known");
  3800.       TREE_TYPE (decl) = error_mark_node;
  3801.     }
  3802.       else if (!TREE_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
  3803.     /* Let debugger know it should output info for this type.  */
  3804.     CLASSTYPE_ASM_WRITTEN (ttype) = 1;
  3805.  
  3806.       if ((TREE_EXTERNAL (decl) || TREE_STATIC (decl))
  3807.       && DECL_SIZE (decl) != 0 && ! TREE_LITERAL (DECL_SIZE (decl)))
  3808.     error_with_decl (decl, "storage size of `%s' isn't constant");
  3809.  
  3810.       if (!TREE_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
  3811.     {
  3812.       int yes = suspend_momentary ();
  3813.  
  3814.       /* If INIT comes from a functional cast, use the cleanup
  3815.          we built for that.  Otherwise, make our own cleanup.  */
  3816.       if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
  3817.           && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
  3818.         {
  3819.           cleanup = TREE_OPERAND (init, 2);
  3820.           init = TREE_OPERAND (init, 0);
  3821.         }
  3822.       else
  3823.         cleanup = maybe_build_cleanup (decl);
  3824.       resume_momentary (yes);
  3825.     }
  3826.     }
  3827.   /* PARM_DECLs get cleanups, too.  */
  3828.   else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
  3829.     {
  3830.       if (temporary)
  3831.     end_temporary_allocation ();
  3832.       cleanup = maybe_build_cleanup (decl);
  3833.       if (temporary)
  3834.     resume_temporary_allocation ();
  3835.     }
  3836.  
  3837.   /* Output the assembler code and/or RTL code for variables and functions,
  3838.      unless the type is an undefined structure or union.
  3839.      If not, it will get done when the type is completed.  */
  3840.  
  3841.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
  3842.       || TREE_CODE (decl) == RESULT_DECL)
  3843.     {
  3844.       int toplev = current_binding_level == global_binding_level;
  3845.       int was_temp
  3846.     = ((flag_traditional
  3847.         || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
  3848.        && allocation_temporary_p ());
  3849.  
  3850.       if (was_temp)
  3851.     end_temporary_allocation ();
  3852.  
  3853.       /* If we are in need of a cleanup, get out of any implicit
  3854.      handlers that have been established so far.  */
  3855.       if (cleanup && current_binding_level->parm_flag == 3)
  3856.     {
  3857.       pop_implicit_try_blocks (decl);
  3858.       current_binding_level->more_exceptions_ok = 0;
  3859.     }
  3860.  
  3861.       if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
  3862.     make_decl_rtl (decl, 0, toplev);
  3863.       else if (TREE_CODE (decl) == VAR_DECL
  3864.            && TREE_READONLY (decl)
  3865.            && DECL_INITIAL (decl) != 0
  3866.            && DECL_INITIAL (decl) != error_mark_node
  3867.            && DECL_INITIAL (decl) != empty_init_node)
  3868.     {
  3869.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  3870.  
  3871.       if (asmspec)
  3872.         DECL_ASSEMBLER_NAME (decl) = asmspec;
  3873.  
  3874.       if (! toplev
  3875.           && TREE_STATIC (decl)
  3876.           && ! TREE_VOLATILE (decl)
  3877.           && ! TREE_PUBLIC (decl)
  3878.           && ! TREE_EXTERNAL (decl)
  3879.           && ! TYPE_NEEDS_DESTRUCTOR (type)
  3880.           && DECL_MODE (decl) != BLKmode)
  3881.         {
  3882.           /* If this variable is really a constant, then fill its DECL_RTL
  3883.          slot with something which won't take up storage.
  3884.          If something later should take its address, we can always give
  3885.          it legitimate RTL at that time.  */
  3886.           DECL_RTL (decl) = (struct rtx_def *)gen_reg_rtx (DECL_MODE (decl));
  3887.           store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
  3888.           TREE_ASM_WRITTEN (decl) = 1;
  3889.         }
  3890.       else if (toplev)
  3891.         {
  3892.           /* Keep GCC from complaining that this variable
  3893.          is defined but never used.  */
  3894.           TREE_INLINE (decl) = 1;
  3895.           /* If this is a static const, change its apparent linkage
  3896.          if it belongs to a #pragma interface.  */
  3897.           if (TREE_STATIC (decl) && interface_unknown == 0)
  3898.         {
  3899.           if (interface_only)
  3900.             {
  3901.               TREE_STATIC (decl) = 0;
  3902.               TREE_EXTERNAL (decl) = 1;
  3903.             }
  3904.           else
  3905.             {
  3906.               TREE_PUBLIC (decl) = 1;
  3907.               /* Marking it used will cause it to be written.  */
  3908.               TREE_USED (decl) = 1;
  3909.             }
  3910.         }
  3911.           make_decl_rtl (decl, asmspec, toplev);
  3912.         }
  3913.       else
  3914.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  3915.     }
  3916.       else if (TREE_CODE (decl) == VAR_DECL
  3917.            && DECL_LANG_SPECIFIC (decl)
  3918.            && DECL_IN_AGGR_P (decl))
  3919.     {
  3920.       if (TREE_STATIC (decl))
  3921.         if (init == 0 && TYPE_NEEDS_CONSTRUCTING (type))
  3922.           {
  3923.         TREE_EXTERNAL (decl) = 1;
  3924.         make_decl_rtl (decl, asmspec, 1);
  3925.           }
  3926.         else
  3927.           rest_of_decl_compilation (decl, asmspec, toplev, 0);
  3928.       else
  3929.         /* Just a constant field.  Should not need any rtl.  */
  3930.         goto finish_end0;
  3931.     }
  3932.       else
  3933.     rest_of_decl_compilation (decl, asmspec, toplev, 0);
  3934.  
  3935.       if (was_temp)
  3936.     resume_temporary_allocation ();
  3937.  
  3938.       if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  3939.     abstract_virtuals_error (decl, type);
  3940.       else if (TREE_CODE (type) == FUNCTION_TYPE
  3941.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  3942.            && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
  3943.     abstract_virtuals_error (decl, TREE_TYPE (type));
  3944.  
  3945.       if (TREE_CODE (decl) == FUNCTION_DECL)
  3946.     {
  3947.       /* C++: Handle overloaded functions with default parameters.  */
  3948.       if (DECL_OVERLOADED (decl))
  3949.         {
  3950.           tree parmtypes = TYPE_ARG_TYPES (type);
  3951.           tree prev = NULL_TREE;
  3952.           char *original_name = IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (decl));
  3953.           struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
  3954.           /* All variants will share an uncollectable lang_decl.  */
  3955.           copy_decl_lang_specific (decl);
  3956.  
  3957.           while (parmtypes && parmtypes != void_list_node)
  3958.         {
  3959.           if (TREE_PURPOSE (parmtypes))
  3960.             {
  3961.               tree fnname, fndecl;
  3962.               tree *argp = prev
  3963.             ? & TREE_CHAIN (prev)
  3964.               : & TYPE_ARG_TYPES (type);
  3965.  
  3966.               *argp = NULL_TREE;
  3967.               fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0);
  3968.               *argp = parmtypes;
  3969.               fndecl = build_decl (FUNCTION_DECL, fnname, type);
  3970.               TREE_EXTERNAL (fndecl) = TREE_EXTERNAL (decl);
  3971.               TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
  3972.               TREE_INLINE (fndecl) = TREE_INLINE (decl);
  3973.               /* Keep G++ from thinking this function is unused.
  3974.              It is only used to speed up search in name space.  */
  3975.               TREE_USED (fndecl) = 1;
  3976.               TREE_ASM_WRITTEN (fndecl) = 1;
  3977.               DECL_INITIAL (fndecl) = NULL_TREE;
  3978.               DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
  3979.               fndecl = pushdecl (fndecl);
  3980.               DECL_INITIAL (fndecl) = error_mark_node;
  3981.               DECL_RTL (fndecl) = DECL_RTL (decl);
  3982.             }
  3983.           prev = parmtypes;
  3984.           parmtypes = TREE_CHAIN (parmtypes);
  3985.         }
  3986.           DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
  3987.         }
  3988.     }
  3989.       else if (TREE_EXTERNAL (decl))
  3990.     ;
  3991.       else if (TREE_STATIC (decl))
  3992.     {
  3993.       /* Cleanups for static variables are handled by `finish_file'.  */
  3994.       if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
  3995.         expand_static_init (decl, init);
  3996.     }
  3997.       else if (current_binding_level != global_binding_level)
  3998.     {
  3999.       /* This is a declared decl which must live until the
  4000.          end of the binding contour.  It may need a cleanup.  */
  4001.  
  4002.       /* Recompute the RTL of a local array now
  4003.          if it used to be an incomplete type.  */
  4004.       if (was_incomplete && ! TREE_STATIC (decl))
  4005.         {
  4006.           /* If we used it already as memory, it must stay in memory.  */
  4007.           TREE_ADDRESSABLE (decl) = TREE_USED (decl);
  4008.           /* If it's still incomplete now, no init will save it.  */
  4009.           if (DECL_SIZE (decl) == 0)
  4010.         DECL_INITIAL (decl) = 0;
  4011.           expand_decl (decl);
  4012.         }
  4013.       else if (! TREE_ASM_WRITTEN (decl)
  4014.            && (TYPE_SIZE (type) != 0 || TREE_CODE (type) == ARRAY_TYPE))
  4015.         {
  4016.           /* Do this here, because we did not expand this decl's
  4017.          rtl in start_decl.  */
  4018.           if (DECL_RTL (decl) == 0)
  4019.         expand_decl (decl);
  4020.           else if (cleanup)
  4021.         {
  4022.           expand_decl_cleanup (NULL_TREE, cleanup);
  4023.           /* Cleanup used up here.  */
  4024.           cleanup = 0;
  4025.         }
  4026.         }
  4027.  
  4028.       if (DECL_SIZE (decl) && type != error_mark_node)
  4029.         {
  4030.           /* Compute and store the initial value.  */
  4031.           expand_decl_init (decl);
  4032.  
  4033.           if (init || TYPE_NEEDS_CONSTRUCTING (type))
  4034.         {
  4035.           emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  4036.           expand_aggr_init (decl, init, 0);
  4037.         }
  4038.  
  4039.           /* Set this to 0 so we can tell whether an aggregate
  4040.          which was initialized was ever used.  */
  4041.           if (TYPE_NEEDS_CONSTRUCTING (type))
  4042.         TREE_USED (decl) = 0;
  4043.  
  4044.           /* Store the cleanup, if there was one.  */
  4045.           if (cleanup)
  4046.         {
  4047.           if (! expand_decl_cleanup (decl, cleanup))
  4048.             error_with_decl (decl, "parser lost in parsing declaration of `%s'");
  4049.         }
  4050.         }
  4051.     }
  4052.     finish_end0:
  4053.  
  4054.       /* Undo call to `pushclass' that was done in `start_decl'
  4055.      due to initialization of qualified member variable.
  4056.      I.e., Foo::x = 10;  */
  4057.       if (TREE_CODE (decl) == VAR_DECL && DECL_CONTEXT (decl))
  4058.     popclass (1);
  4059.     }
  4060.  
  4061.  finish_end:
  4062.  
  4063.   /* Resume permanent allocation, if not within a function.  */
  4064.   if (temporary && current_binding_level == global_binding_level)
  4065.     {
  4066.       permanent_allocation ();
  4067. #if 0
  4068.       /* @@ I don't know whether this is true for GNU C++.  */
  4069.       /* We need to remember that this array HAD an initialization,
  4070.      but discard the actual nodes, since they are temporary anyway.  */
  4071.       if (DECL_INITIAL (decl) != 0)
  4072.     DECL_INITIAL (decl) = error_mark_node;
  4073. #endif
  4074.     }
  4075.   if (was_readonly)
  4076.     TREE_READONLY (decl) = 1;
  4077. }
  4078.  
  4079. static void
  4080. expand_static_init (decl, init)
  4081.      tree decl;
  4082.      tree init;
  4083. {
  4084.   tree oldstatic = value_member (decl, static_aggregates);
  4085.   if (oldstatic)
  4086.     {
  4087.       if (TREE_PURPOSE (oldstatic))
  4088.     error_with_decl (decl, "multiple initializations given for `%s'");
  4089.     }
  4090.   else if (current_binding_level != global_binding_level)
  4091.     {
  4092.       /* Emit code to perform this initialization but once.  */
  4093.       tree temp = get_temp_name (integer_type_node, 1);
  4094.       rest_of_decl_compilation (temp, NULL_TREE, 0, 0);
  4095.       expand_start_cond (build_binary_op (EQ_EXPR, temp, integer_zero_node), 0);
  4096.       expand_assignment (temp, integer_one_node, 0, 0);
  4097.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  4098.     {
  4099.       expand_aggr_init (decl, init, 0);
  4100.       do_pending_stack_adjust ();
  4101.     }
  4102.       else
  4103.     expand_assignment (decl, init, 0, 0);
  4104.       expand_end_cond ();
  4105.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
  4106.     {
  4107.       static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
  4108.       TREE_STATIC (static_aggregates) = 1;
  4109.     }
  4110.     }
  4111.   else
  4112.     {
  4113.       /* This code takes into account memory allocation
  4114.      policy of `start_decl'.  Namely, if TYPE_NEEDS_CONSTRUCTING
  4115.      does not hold for this object, then we must make permanent
  4116.      the storage currently in the temporary obstack.  */
  4117.       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  4118.     preserve_initializer ();
  4119.       static_aggregates = perm_tree_cons (init, decl, static_aggregates);
  4120.     }
  4121. }
  4122.  
  4123. /* Make TYPE a complete type based on INITIAL_VALUE.
  4124.    Return 0 if successful, 1 if INITIAL_VALUE can't be decyphered,
  4125.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  4126.  
  4127. int
  4128. complete_array_type (type, initial_value, do_default)
  4129.      tree type;
  4130.      tree initial_value;
  4131.      int do_default;
  4132. {
  4133.   register tree maxindex = NULL_TREE;
  4134.   int value = 0;
  4135.   int temporary = (TREE_PERMANENT (type) && allocation_temporary_p ());
  4136.  
  4137.   /* Don't put temporary nodes in permanent type.  */
  4138.   if (temporary)
  4139.     end_temporary_allocation ();
  4140.  
  4141.   if (initial_value)
  4142.     {
  4143.       /* Note MAXINDEX  is really the maximum index,
  4144.      one less than the size.  */
  4145.       if (TREE_CODE (initial_value) == STRING_CST)
  4146.     maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
  4147.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  4148.     {
  4149.       register int nelts
  4150.         = list_length (CONSTRUCTOR_ELTS (initial_value));
  4151.       maxindex = build_int_2 (nelts - 1, 0);
  4152.     }
  4153.       else
  4154.     {
  4155.       /* Make an error message unless that happened already.  */
  4156.       if (initial_value != error_mark_node)
  4157.         value = 1;
  4158.  
  4159.       /* Prevent further error messages.  */
  4160.       maxindex = build_int_2 (1, 0);
  4161.     }
  4162.     }
  4163.  
  4164.   if (!maxindex)
  4165.     {
  4166.       if (do_default)
  4167.     maxindex = build_int_2 (1, 0);
  4168.       value = 2;
  4169.     }
  4170.  
  4171.   if (maxindex)
  4172.     {
  4173.       TYPE_DOMAIN (type) = build_index_type (maxindex);
  4174.       if (!TREE_TYPE (maxindex))
  4175.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  4176.     }
  4177.  
  4178.   /* Lay out the type now that we can get the real answer.  */
  4179.  
  4180.   layout_type (type);
  4181.  
  4182.   if (temporary)
  4183.     resume_temporary_allocation ();
  4184.  
  4185.   return value;
  4186. }
  4187.  
  4188. /* Return zero if something is declared to be a member of type
  4189.    CTYPE when in the context of CUR_TYPE.  STRING is the error
  4190.    message to print in that case.  Otherwise, quietly return 1.  */
  4191. static int
  4192. member_function_or_else (ctype, cur_type, string)
  4193.      tree ctype, cur_type;
  4194.      char *string;
  4195. {
  4196.   if (ctype && ctype != cur_type)
  4197.     {
  4198.       error (string, TYPE_NAME_STRING (ctype));
  4199.       return 0;
  4200.     }
  4201.   return 1;
  4202. }
  4203.  
  4204. /* Subroutine of `grokdeclarator'.  */
  4205.  
  4206. /* CTYPE is class type, or null if non-class.
  4207.    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
  4208.    or METHOD_TYPE.
  4209.    DECLARATOR is the function's name.
  4210.    VIRTUALP is truthvalue of whether the function is virtual or not.
  4211.    FLAGS are to be passed through to `grokclassfn'.
  4212.    QUALS are qualifiers indicating whether the function is `const'
  4213.    or `volatile'.
  4214.    RAISES is a list of exceptions that this function can raise.
  4215.    CHECK is 1 if we must find this method in CTYPE, 0 if we should
  4216.    not look, and -1 if we should not call `grokclassfn' at all.  */
  4217. static tree
  4218. grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check)
  4219.      tree ctype, type;
  4220.      tree declarator;
  4221.      int virtualp;
  4222.      enum overload_flags flags;
  4223.      tree quals, raises;
  4224.      int check;
  4225. {
  4226.   tree cname, decl;
  4227.   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
  4228.  
  4229.   if (ctype)
  4230.     cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  4231.       ? DECL_NAME (TYPE_NAME (ctype)) : TYPE_NAME (ctype);
  4232.   else
  4233.     cname = NULL_TREE;
  4234.  
  4235.   if (raises)
  4236.     {
  4237.       type = build_exception_variant (ctype, type, raises);
  4238.       raises = TYPE_RAISES_EXCEPTIONS (type);
  4239.     }
  4240.   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
  4241.   if (staticp)
  4242.     {
  4243.       DECL_STATIC_FUNCTION_P (decl) = 1;
  4244.       DECL_STATIC_CONTEXT (decl) = ctype;
  4245.     }
  4246.   TREE_EXTERNAL (decl) = 1;
  4247.   if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
  4248.     {
  4249.       /* Dont have DECL_ORIGINAL_NAME yet, so we cannot pretty print it.  */
  4250.       error ("functions cannot have method qualifiers");
  4251.       quals = NULL_TREE;
  4252.     }
  4253.  
  4254.   /* Caller will do the rest of this.  */
  4255.   if (check < 0)
  4256.     return decl;
  4257.  
  4258.   if (flags == NO_SPECIAL && ctype && declarator == cname)
  4259.     {
  4260.       tree tmp;
  4261.       /* Just handle constructors here.  We could do this
  4262.      inside the following if stmt, but I think
  4263.      that the code is more legible by breaking this
  4264.      case out.  See comments below for what each of
  4265.      the following calls is supposed to do.  */
  4266.       DECL_CONSTRUCTOR_P (decl) = 1;
  4267.  
  4268.       grokclassfn (ctype, declarator, decl, flags, check, quals);
  4269.       grok_ctor_properties (ctype, decl);
  4270.       if (check == 0)
  4271.     {
  4272.       tmp = lookup_name (DECL_NAME (decl));
  4273.       if (tmp == 0)
  4274.         IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl)) = decl;
  4275.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  4276.         error_with_decl (decl, "inconsistant declarations for `%s'");
  4277.       else
  4278.         {
  4279.           duplicate_decls (decl, tmp);
  4280.           decl = tmp;
  4281.         }
  4282.       make_decl_rtl (decl, NULL_TREE, 1);
  4283.     }
  4284.     }
  4285.   else
  4286.     {
  4287.       tree tmp;
  4288.       int i;
  4289.  
  4290.       /* Function gets the ugly name, field gets the nice one.
  4291.      This call may change the type of the function (because
  4292.      of default parameters)!
  4293.      
  4294.      Wrappers get field names which will not conflict
  4295.      with constructors and destructors.  */
  4296.       if (ctype != NULL_TREE)
  4297.     grokclassfn (ctype, cname, decl, flags, check, quals);
  4298.  
  4299.       if (OPERATOR_NAME_P (DECL_NAME (decl)))
  4300.     {
  4301.       TREE_OPERATOR (decl) = 1;
  4302.       grok_op_properties (decl);
  4303.     }
  4304.  
  4305.       if (ctype == NULL_TREE || check)
  4306.     return decl;
  4307.  
  4308.       /* Now install the declaration of this function so that
  4309.      others may find it (esp. its DECL_FRIENDLIST).
  4310.      Pretend we are at top level, we will get true
  4311.      reference later, perhaps.  */
  4312.       tmp = lookup_name (DECL_NAME (decl));
  4313.       if (tmp == 0)
  4314.     IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl)) = decl;
  4315.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  4316.     error_with_decl (decl, "inconsistant declarations for `%s'");
  4317.       else
  4318.     {
  4319.       duplicate_decls (decl, tmp);
  4320.       decl = tmp;
  4321.     }
  4322.       make_decl_rtl (decl, NULL_TREE, 1);
  4323.  
  4324.       /* If this declaration supersedes the declaration of
  4325.      a method declared virtual in the base class, then
  4326.      mark this field as being virtual as well.  */
  4327.       for (i = 1; i <= CLASSTYPE_N_BASECLASSES (ctype); i++)
  4328.     {
  4329.       tree basetype = CLASSTYPE_BASECLASS (ctype, i);
  4330.       if (TYPE_VIRTUAL_P (basetype) || flag_all_virtual == 1)
  4331.         {
  4332.           tmp = get_first_matching_virtual (basetype, decl,
  4333.                         flags == DTOR_FLAG);
  4334.           if (tmp)
  4335.         {
  4336.           /* The TMP we really want is the one from the deepest
  4337.              baseclass on this path, taking care not to
  4338.              duplicate if we have already found it (via another
  4339.              path to its virtual baseclass.  */
  4340.           if (staticp)
  4341.             {
  4342.               error_with_decl (decl, "method `%s' may not be declared static");
  4343.               error_with_decl (tmp, "(since `%s' declared virtual in base class.)");
  4344.               break;
  4345.             }
  4346.           virtualp = 1;
  4347.  
  4348.           if ((TYPE_USES_VIRTUAL_BASECLASSES (basetype)
  4349.                || TYPE_USES_MULTIPLE_INHERITANCE (ctype))
  4350.               && TYPE_MAIN_VARIANT (basetype) != DECL_VCONTEXT (tmp))
  4351.             tmp = get_first_matching_virtual (DECL_VCONTEXT (tmp),
  4352.                               decl, flags == DTOR_FLAG);
  4353.           if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE)
  4354.             {
  4355.               /* The argument types may have changed... */
  4356.               tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  4357.               tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
  4358.  
  4359.               argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
  4360.                           TREE_CHAIN (argtypes));
  4361.               /* But the return type has not.  */
  4362.               type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
  4363.               if (raises)
  4364.             {
  4365.               type = build_exception_variant (ctype, type, raises);
  4366.               raises == TYPE_RAISES_EXCEPTIONS (type);
  4367.             }
  4368.               TREE_TYPE (decl) = type;
  4369.               SET_DECL_VINDEX (decl, tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)));
  4370.             }
  4371.         }
  4372.         }
  4373.     }
  4374.       if (virtualp)
  4375.     {
  4376.       DECL_VIRTUAL_P (decl) = 1;
  4377.       DECL_VIRTUAL_P (declarator) = 1;
  4378.       if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
  4379.           && (write_virtuals == 2
  4380.           || (write_virtuals == 3
  4381.               && ! CLASSTYPE_INTERFACE_UNKNOWN (ctype))))
  4382.         TREE_PUBLIC (decl) = 1;
  4383.     }
  4384.     }
  4385.   return decl;
  4386. }
  4387.  
  4388. static tree
  4389. grokvardecl (ctype, type, declarator, specbits, initialized)
  4390.      tree ctype, type;
  4391.      tree declarator;
  4392.      int specbits;
  4393. {
  4394.   tree decl;
  4395.  
  4396.   if (TREE_CODE (type) == OFFSET_TYPE)
  4397.     {
  4398.       /* If you declare a static member so that it
  4399.      can be initialized, the code will reach here.  */
  4400.       tree field = lookup_field (TYPE_OFFSET_BASETYPE (type),
  4401.                  declarator, 0);
  4402.       if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
  4403.     {
  4404.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  4405.       error ("`%s' is not a static member of class `%s'",
  4406.          IDENTIFIER_POINTER (declarator),
  4407.          TYPE_NAME_STRING (basetype));
  4408.       type = TREE_TYPE (type);
  4409.       decl = build_decl (VAR_DECL, declarator, type);
  4410.       DECL_CONTEXT (decl) = basetype;
  4411.     }
  4412.       else
  4413.     {
  4414.       decl = field;
  4415.       if (initialized && DECL_INITIAL (decl)
  4416.           /* Complain about multiply-initialized
  4417.          member variables, but don't be faked
  4418.          out if initializer is faked up from `empty_init_node'.  */
  4419.           && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  4420.           || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE))
  4421.         error_with_aggr_type (DECL_CONTEXT (decl),
  4422.                   "multiple initializations of static member `%s::%s'",
  4423.                   IDENTIFIER_POINTER (DECL_NAME (decl)));
  4424.     }
  4425.     }
  4426.   else decl = build_decl (VAR_DECL, declarator, type);
  4427.  
  4428.   if (specbits & (1 << (int) RID_EXTERN))
  4429.     {
  4430.       DECL_EXTERNAL (decl) = 1;
  4431.       TREE_EXTERNAL (decl) = !initialized;
  4432.     }
  4433.  
  4434.   /* In class context, static means one per class,
  4435.      public visibility, and static storage.  */
  4436.   if (DECL_FIELD_CONTEXT (decl) != 0
  4437.       && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
  4438.     {
  4439.       TREE_PUBLIC (decl) = 1;
  4440.       TREE_STATIC (decl) = 1;
  4441.     }
  4442.   /* At top level, either `static' or no s.c. makes a definition
  4443.      (perhaps tentative), and absence of `static' makes it public.  */
  4444.   else if (current_binding_level == global_binding_level)
  4445.     {
  4446.       TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
  4447.       TREE_STATIC (decl) = ! TREE_EXTERNAL (decl);
  4448.     }
  4449.   /* Not at top level, only `static' makes a static definition.  */
  4450.   else
  4451.     {
  4452.       TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
  4453.       TREE_PUBLIC (decl) = TREE_EXTERNAL (decl);
  4454.       /* `extern' with initialization is invalid if not at top level.  */
  4455.       if ((specbits & (1 << (int) RID_EXTERN)) && initialized)
  4456.     error_with_decl (decl, "`%s' has both `extern' and initializer");
  4457.     }
  4458.   return decl;
  4459. }
  4460.  
  4461. /* Given declspecs and a declarator,
  4462.    determine the name and type of the object declared
  4463.    and construct a ..._DECL node for it.
  4464.    (In one case we can return a ..._TYPE node instead.
  4465.     For invalid input we sometimes return 0.)
  4466.  
  4467.    DECLSPECS is a chain of tree_list nodes whose value fields
  4468.     are the storage classes and type specifiers.
  4469.  
  4470.    DECL_CONTEXT says which syntactic context this declaration is in:
  4471.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  4472.      FUNCDEF for a function definition.  Like NORMAL but a few different
  4473.       error messages in each case.  Return value may be zero meaning
  4474.       this definition is too screwy to try to parse.
  4475.      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
  4476.       handle member functions (which have FIELD context).
  4477.       Return value may be zero meaning this definition is too screwy to
  4478.       try to parse.
  4479.      PARM for a parameter declaration (either within a function prototype
  4480.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  4481.      TYPENAME if for a typename (in a cast or sizeof).
  4482.       Don't make a DECL node; just return the ..._TYPE node.
  4483.      FIELD for a struct or union field; make a FIELD_DECL.
  4484.    INITIALIZED is 1 if the decl has an initializer.
  4485.  
  4486.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  4487.    It may also be so in the PARM case, for a prototype where the
  4488.    argument type is specified but not the name.
  4489.  
  4490.    This function is where the complicated C meanings of `static'
  4491.    and `extern' are intrepreted.
  4492.  
  4493.    For C++, if there is any monkey business to do, the function which
  4494.    calls this one must do it, i.e., prepending instance variables,
  4495.    renaming overloaded function names, etc.
  4496.  
  4497.    Note that for this C++, it is an error to define a method within a class
  4498.    which does not belong to that class.
  4499.  
  4500.    Execpt in the case where SCOPE_REFs are implicitly known (such as
  4501.    methods within a class being redundantly qualified),
  4502.    declarations which involve SCOPE_REFs are returned as SCOPE_REFs
  4503.    (class_name::decl_name).  The caller must also deal with this.
  4504.  
  4505.    If a constructor or destructor is seen, and the context is FIELD,
  4506.    then the type gains the attribtue TREE_HAS_x.  If such a declaration
  4507.    is erroneous, NULL_TREE is returned.
  4508.  
  4509.    QUALS is used only for FUNCDEF and MEMFUNCDEF cases.  For a member
  4510.    function, these are the qualifiers to give to the `this' pointer.
  4511.  
  4512.    May return void_type_node if the declarator turned out to be a friend.
  4513.    See grokfield for details.  */
  4514.  
  4515. enum return_types { return_normal, return_ctor, return_dtor, return_conversion, };
  4516.  
  4517. tree
  4518. grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
  4519.      tree declspecs;
  4520.      tree declarator;
  4521.      enum decl_context decl_context;
  4522.      int initialized;
  4523.      tree raises;
  4524. {
  4525.   int specbits = 0;
  4526.   int nclasses = 0;
  4527.   tree spec;
  4528.   tree type = NULL_TREE;
  4529.   int longlong = 0;
  4530.   int constp;
  4531.   int volatilep;
  4532.   int virtualp, friendp, inlinep, staticp;
  4533.   int explicit_int = 0;
  4534.   int explicit_char = 0;
  4535.   int explicit_type = 0;
  4536.   char *name;
  4537.   tree typedef_type = 0;
  4538.   int funcdef_flag = 0;
  4539.   int resume_temporary = 0;
  4540.   enum tree_code innermost_code = ERROR_MARK;
  4541.   /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
  4542.      All FIELD_DECLs we build here have `init' put into their DECL_INITIAL.  */
  4543.   tree init = 0;
  4544.  
  4545.   /* Keep track of what sort of function is being processed
  4546.      so that we can warn about default return values, or explicit
  4547.      return values which do not match prescribed defaults.  */
  4548.   enum return_types return_type = return_normal;
  4549.  
  4550.   tree dname = NULL_TREE;
  4551.   tree ctype = current_class_type;
  4552.   tree ctor_return_type = NULL_TREE;
  4553.   enum overload_flags flags = NO_SPECIAL;
  4554.   int seen_scope_ref = 0;
  4555.   tree quals = 0;
  4556.  
  4557.   if (decl_context == FUNCDEF)
  4558.     funcdef_flag = 1, decl_context = NORMAL;
  4559.   else if (decl_context == MEMFUNCDEF)
  4560.     funcdef_flag = -1, decl_context = FIELD;
  4561.  
  4562.   if (flag_traditional && allocation_temporary_p ())
  4563.     {
  4564.       resume_temporary = 1;
  4565.       end_temporary_allocation ();
  4566.     }
  4567.  
  4568.   /* Look inside a declarator for the name being declared
  4569.      and get it as a string, for an error message.  */
  4570.   {
  4571.     tree type, last = 0;
  4572.     register tree decl = declarator;
  4573.     name = 0;
  4574.  
  4575.     /* If we see something of the form `aggr_type xyzzy (a, b, c)'
  4576.        it is either an old-style function declaration or a call to
  4577.        a constructor.  The following conditional makes recognizes this
  4578.        case as being a call to a constructor.  Too bad if it is not.  */
  4579.  
  4580.     /* For Doug Lea, also grok `aggr_type xyzzy (a, b, c)[10][10][10]'.  */
  4581.     while (decl && TREE_CODE (decl) == ARRAY_REF)
  4582.       {
  4583.     last = decl;
  4584.     decl = TREE_OPERAND (decl, 0);
  4585.       }
  4586.  
  4587.     if (current_lang_name == lang_name_cplusplus
  4588.         && decl && declspecs
  4589.         && TREE_CODE (decl) == CALL_EXPR
  4590.         && TREE_OPERAND (decl, 0)
  4591.         && (TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
  4592.         || TREE_CODE (TREE_OPERAND (decl, 0)) == SCOPE_REF))
  4593.       {
  4594.         type = TREE_CODE (TREE_VALUE (declspecs)) == IDENTIFIER_NODE
  4595.           ? lookup_name (TREE_VALUE (declspecs)) :
  4596.         (IS_AGGR_TYPE (TREE_VALUE (declspecs))
  4597.          ? TYPE_NAME (TREE_VALUE (declspecs)) : NULL_TREE);
  4598.  
  4599.         if (type && TREE_CODE (type) == TYPE_DECL
  4600.             && IS_AGGR_TYPE (TREE_TYPE (type))
  4601.             && parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
  4602.           {
  4603.             if (decl_context == FIELD
  4604.                 && TREE_CHAIN (TREE_OPERAND (decl, 1)))
  4605.               {
  4606.                 /* That was an initializer list.  */
  4607.                 sorry ("initializer lists for field declarations");
  4608.                 decl = TREE_OPERAND (decl, 0);
  4609.         if (last)
  4610.           {
  4611.             TREE_OPERAND (last, 0) = decl;
  4612.             decl = declarator;
  4613.           }
  4614.                 declarator = decl;
  4615.                 init = error_mark_node;
  4616.                 goto bot;
  4617.               }
  4618.             else
  4619.               {
  4620.         tree init = TREE_OPERAND (decl, 1);
  4621.         if (last)
  4622.           {
  4623.             TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
  4624.             if (pedantic && init)
  4625.               error ("arrays cannot take initializers");
  4626.           }
  4627.         else
  4628.           declarator = TREE_OPERAND (declarator, 0);
  4629.                 decl = start_decl (declarator, declspecs, 1, NULL_TREE);
  4630.                 finish_decl (decl, init, NULL_TREE);
  4631.                 return 0;
  4632.               }
  4633.           }
  4634.  
  4635.         if (parmlist_is_random (TREE_OPERAND (decl, 1)))
  4636.           {
  4637.         decl = TREE_OPERAND (decl, 0);
  4638.         if (TREE_CODE (decl) == SCOPE_REF)
  4639.           decl = TREE_OPERAND (decl, 1);
  4640.         if (TREE_CODE (decl) == IDENTIFIER_NODE)
  4641.           name = IDENTIFIER_POINTER (decl);
  4642.         if (name)
  4643.           error ("bad parameter list specification for function `%s'",
  4644.              name);
  4645.         else
  4646.           error ("bad parameter list specification for function");
  4647.             return 0;
  4648.           }
  4649.       bot:
  4650.         ;
  4651.       }
  4652.     else
  4653.       /* It didn't look like we thought it would, leave the ARRAY_REFs on.  */
  4654.       decl = declarator;
  4655.  
  4656.     while (decl)
  4657.       switch (TREE_CODE (decl))
  4658.         {
  4659.     case WRAPPER_EXPR:      /* for C++ wrappers.  */
  4660.       if (current_lang_name != lang_name_cplusplus)
  4661.         error ("wrapper declared in \"%s\" language context",
  4662.            IDENTIFIER_POINTER (current_lang_name));
  4663.  
  4664.       ctype = NULL_TREE;
  4665.       assert (flags == NO_SPECIAL);
  4666.       flags = WRAPPER_FLAG;
  4667.       decl = TREE_OPERAND (decl, 0);
  4668.       break;
  4669.  
  4670.     case ANTI_WRAPPER_EXPR: /* for C++ wrappers.  */
  4671.       if (current_lang_name != lang_name_cplusplus)
  4672.         error ("anti-wrapper declared in \"%s\" language context",
  4673.            IDENTIFIER_POINTER (current_lang_name));
  4674.  
  4675.       ctype = NULL_TREE;
  4676.       assert (flags == NO_SPECIAL);
  4677.       flags = ANTI_WRAPPER_FLAG;
  4678.       decl = TREE_OPERAND (decl, 0);
  4679.       break;
  4680.  
  4681.     case COND_EXPR:
  4682.       if (current_lang_name != lang_name_cplusplus)
  4683.         error ("wrapper predicate declared in \"%s\" language context",
  4684.            IDENTIFIER_POINTER (current_lang_name));
  4685.  
  4686.       ctype = NULL_TREE;
  4687.       assert (flags == WRAPPER_FLAG);
  4688.       flags = WRAPPER_PRED_FLAG;
  4689.       decl = TREE_OPERAND (decl, 0);
  4690.       break;
  4691.  
  4692.     case BIT_NOT_EXPR:      /* for C++ destructors!  */
  4693.       {
  4694.         tree name = TREE_OPERAND (decl, 0);
  4695.         tree rename = NULL_TREE;
  4696.  
  4697.         if (current_lang_name != lang_name_cplusplus)
  4698.           error ("destructor declared in \"%s\" language context",
  4699.              IDENTIFIER_POINTER (current_lang_name));
  4700.  
  4701.         assert (flags == NO_SPECIAL);
  4702.         flags = DTOR_FLAG;
  4703.         return_type = return_dtor;
  4704.         assert (TREE_CODE (name) == IDENTIFIER_NODE);
  4705.         if (ctype == NULL_TREE)
  4706.           {
  4707.         if (current_class_type == NULL_TREE)
  4708.           {
  4709.             error ("destructors must be member functions");
  4710.             flags = NO_SPECIAL;
  4711.           }
  4712.         else if (current_class_name != name)
  4713.           rename = current_class_name;
  4714.           }
  4715.         else if (DECL_NAME (TYPE_NAME (ctype)) != name)
  4716.           rename = DECL_NAME (TYPE_NAME (ctype));
  4717.  
  4718.         if (rename)
  4719.           {
  4720.         error ("destructor `%s' must match class name `%s'",
  4721.                IDENTIFIER_POINTER (name),
  4722.                IDENTIFIER_POINTER (rename));
  4723.         TREE_OPERAND (decl, 0) = rename;
  4724.           }
  4725.         decl = name;
  4726.       }
  4727.       break;
  4728.  
  4729.     case ADDR_EXPR:         /* C++ reference declaration */
  4730.       /* fall through */
  4731.     case ARRAY_REF:
  4732.     case INDIRECT_REF:
  4733.       ctype = NULL_TREE;
  4734.       innermost_code = TREE_CODE (decl);
  4735.       decl = TREE_OPERAND (decl, 0);
  4736.       break;
  4737.  
  4738.     case CALL_EXPR:
  4739.       innermost_code = TREE_CODE (decl);
  4740.       decl = TREE_OPERAND (decl, 0);
  4741.       if (decl_context == FIELD && ctype == NULL_TREE)
  4742.         ctype = current_class_type;
  4743.       if (ctype != NULL_TREE
  4744.           && decl != NULL_TREE && flags != DTOR_FLAG
  4745.           && TREE_TYPE (decl) && TREE_TYPE (TREE_TYPE (decl)) == ctype)
  4746.         {
  4747.           return_type = return_ctor;
  4748.           ctor_return_type = ctype;
  4749.         }
  4750.       ctype = NULL_TREE;
  4751.       break;
  4752.  
  4753.     case IDENTIFIER_NODE:
  4754.       dname = decl;
  4755.       name = IDENTIFIER_POINTER (decl);
  4756.       decl = 0;
  4757.       break;
  4758.  
  4759.     case RECORD_TYPE:
  4760.     case UNION_TYPE:
  4761.     case ENUMERAL_TYPE:
  4762.       /* Parse error puts this typespec where
  4763.          a declarator should go.  */
  4764.       error ("declarator name missing");
  4765.       dname = TYPE_NAME (decl);
  4766.       if (dname && TREE_CODE (dname) == TYPE_DECL)
  4767.         dname = DECL_NAME (dname);
  4768.       name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
  4769.       declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
  4770.       decl = 0;
  4771.       break;
  4772.  
  4773.     case OP_IDENTIFIER:
  4774.       if (current_lang_name != lang_name_cplusplus)
  4775.         error ("operator declared in \"%s\" language context",
  4776.            IDENTIFIER_POINTER (current_lang_name));
  4777.  
  4778.       /* C++ operators: if these are member functions, then
  4779.          they overload the same way normal methods do.  However,
  4780.          if they are declared outside of a classes scope, then
  4781.          they are implicitly treated like `friends', i.e.,
  4782.          they do not take any unseen arguments.  */
  4783.       assert (flags == NO_SPECIAL);
  4784.       flags = OP_FLAG;
  4785.       name = "operator name";
  4786.       decl = 0;
  4787.       break;
  4788.  
  4789.     case TYPE_EXPR:
  4790.       if (current_lang_name != lang_name_cplusplus)
  4791.         error ("type conversion operator declared in \"%s\" language context",
  4792.            IDENTIFIER_POINTER (current_lang_name));
  4793.  
  4794.       ctype = NULL_TREE;
  4795.       assert (flags == NO_SPECIAL);
  4796.       flags = TYPENAME_FLAG;
  4797.       name = "operator <typename>";
  4798.       /* Go to the absdcl.  */
  4799.       decl = TREE_OPERAND (decl, 0);
  4800.       return_type = return_conversion;
  4801.       break;
  4802.  
  4803.       /* C++ extension */
  4804.     case SCOPE_REF:
  4805.       if (current_lang_name != lang_name_cplusplus)
  4806.         error ("member function declared in \"%s\" language context",
  4807.            IDENTIFIER_POINTER (current_lang_name));
  4808.       if (seen_scope_ref == 1)
  4809.         error ("multiple `::' terms in declarator invalid");
  4810.       seen_scope_ref += 1;
  4811.       {
  4812.         /* Perform error checking, and convert class names to types.
  4813.            We may call grokdeclarator multiple times for the same
  4814.            tree structure, so only do the conversion once.  In this
  4815.            case, we have exactly what we want for `ctype'.  */
  4816.         tree cname = TREE_OPERAND (decl, 0);
  4817.         if (cname == NULL_TREE)
  4818.           ctype = NULL_TREE;
  4819.         else if (IS_AGGR_TYPE (cname))
  4820.           ctype = cname;
  4821.         else if (! is_aggr_typedef (cname, 1))
  4822.           {
  4823.         TREE_OPERAND (decl, 0) = 0;
  4824.           }
  4825.         /* Must test TREE_OPERAND (decl, 1), in case user gives
  4826.            us `typedef (class::memfunc)(int); memfunc *memfuncptr;'  */
  4827.         else if (TREE_OPERAND (decl, 1)
  4828.              && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
  4829.           {
  4830.         TREE_OPERAND (decl, 0) = TREE_TYPE (TREE_TYPE (cname));
  4831.           }
  4832.         else if (ctype == NULL_TREE)
  4833.           {
  4834.         ctype = TREE_TYPE (TREE_TYPE (cname));
  4835.         TREE_OPERAND (decl, 0) = ctype;
  4836.           }
  4837.         else
  4838.           {
  4839.         tree new_type = get_base_type (TREE_TYPE (TREE_TYPE (cname)), ctype, 0);
  4840.         if (new_type == NULL_TREE)
  4841.           {
  4842.             error ("type `%s' is not derived from type `%s'",
  4843.                IDENTIFIER_POINTER (cname),
  4844.                TYPE_NAME_STRING (ctype));
  4845.             TREE_OPERAND (decl, 0) = 0;
  4846.           }
  4847.         else
  4848.           {
  4849.             ctype = new_type;
  4850.             TREE_OPERAND (decl, 0) = ctype;
  4851.           }
  4852.           }
  4853.         decl = TREE_OPERAND (decl, 1);
  4854.         if (ctype != NULL_TREE && DECL_NAME (TYPE_NAME (ctype)) == decl)
  4855.           {
  4856.         return_type = return_ctor;
  4857.         ctor_return_type = ctype;
  4858.           }
  4859.       }
  4860.       break;
  4861.  
  4862.     case ERROR_MARK:
  4863.       decl = NULL_TREE;
  4864.       break;
  4865.  
  4866.     default:
  4867.       assert (0);
  4868.     }
  4869.     if (name == 0)
  4870.       name = "type name";
  4871.   }
  4872.  
  4873.   /* A function definition's declarator must have the form of
  4874.      a function declarator.  */
  4875.  
  4876.   if (funcdef_flag && innermost_code != CALL_EXPR)
  4877.     return 0;
  4878.  
  4879.   /* Anything declared one level down from the top level
  4880.      must be one of the parameters of a function
  4881.      (because the body is at least two levels down).  */
  4882.  
  4883.   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
  4884.      by not allowing C++ class definitions to specify their parameters
  4885.      with xdecls (must be spec.d in the parmlist).
  4886.  
  4887.      Since we now wait to push a class scope until we are sure that
  4888.      we are in a legitimate method context, we must set oldcname
  4889.      explicitly (since current_class_name is not yet alive).  */
  4890.  
  4891.   if (decl_context == NORMAL
  4892.       && current_binding_level->level_chain == global_binding_level)
  4893.     decl_context = PARM;
  4894.  
  4895.   /* Look through the decl specs and record which ones appear.
  4896.      Some typespecs are defined as built-in typenames.
  4897.      Others, the ones that are modifiers of other types,
  4898.      are represented by bits in SPECBITS: set the bits for
  4899.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  4900.  
  4901.      If there is a typedef name or a type, store the type in TYPE.
  4902.      This includes builtin typedefs such as `int'.
  4903.  
  4904.      Set EXPLICIT_INT if the type is `int' or `char' and did not
  4905.      come from a user typedef.
  4906.  
  4907.      Set LONGLONG if `long' is mentioned twice.
  4908.  
  4909.      For C++, constructors and destructors have their own fast treatment.  */
  4910.  
  4911.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  4912.     {
  4913.       register int i;
  4914.       register tree id = TREE_VALUE (spec);
  4915.  
  4916.       /* Certain parse errors slip through.  For example,
  4917.      `int class;' is not caught by the parser. Try
  4918.      weakly to recover here.  */
  4919.       if (TREE_CODE (spec) != TREE_LIST)
  4920.     return 0;
  4921.  
  4922.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  4923.     {
  4924.       if (id == ridpointers[(int) RID_INT])
  4925.         {
  4926.           if (type)
  4927.         error ("extraneous `int' ignored");
  4928.           else
  4929.         {
  4930.           explicit_int = 1;
  4931.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  4932.         }
  4933.           goto found;
  4934.         }
  4935.       if (id == ridpointers[(int) RID_CHAR])
  4936.         {
  4937.           if (type)
  4938.         error ("extraneous `char' ignored");
  4939.           else
  4940.         {
  4941.           explicit_char = 1;
  4942.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  4943.         }
  4944.           goto found;
  4945.         }
  4946.       /* C++ aggregate types.  */
  4947.       if (TREE_TYPE (id))
  4948.         {
  4949.           if (type)
  4950.         error ("multiple declarations `%s' and `%s'",
  4951.                IDENTIFIER_POINTER (type),
  4952.                IDENTIFIER_POINTER (id));
  4953.           else
  4954.         type = TREE_TYPE (TREE_TYPE (id));
  4955.           goto found;
  4956.         }
  4957.  
  4958.       for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
  4959.         {
  4960.           if (ridpointers[i] == id)
  4961.         {
  4962.           if (i == (int) RID_LONG && specbits & (1<<i))
  4963.             {
  4964.               if (pedantic)
  4965.             warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
  4966.             else if (longlong)
  4967.               warning ("`long long long' is too long for GCC");
  4968.               else
  4969.             longlong = 1;
  4970.             }
  4971.           else if (specbits & (1 << i))
  4972.             warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
  4973.           specbits |= 1 << i;
  4974.           goto found;
  4975.         }
  4976.         }
  4977.     }
  4978.       if (type)
  4979.     error ("two or more data types in declaration of `%s'", name);
  4980.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  4981.     {
  4982.       register tree t = lookup_name (id);
  4983.       if (!t || TREE_CODE (t) != TYPE_DECL)
  4984.         error ("`%s' fails to be a typedef or built in type",
  4985.            IDENTIFIER_POINTER (id));
  4986.       else type = TREE_TYPE (t);
  4987.     }
  4988.       else if (TREE_CODE (id) != ERROR_MARK)
  4989.     /* Can't change CLASS nodes into RECORD nodes here!  */
  4990.     type = id;
  4991.  
  4992.     found: {}
  4993.     }
  4994.  
  4995.   typedef_type = type;
  4996.  
  4997.   /* No type at all: default to `int', and set EXPLICIT_INT
  4998.      because it was not a user-defined typedef.  */
  4999.   explicit_type = type != 0;
  5000.  
  5001.   if (type == 0)
  5002.     {
  5003.       explicit_int = -1;
  5004.       if (return_type == return_dtor)
  5005.     type = void_type_node;
  5006.       else if (return_type == return_ctor)
  5007.     type = TYPE_POINTER_TO (ctor_return_type);
  5008.       else
  5009.     {
  5010.       if (funcdef_flag && warn_return_type
  5011.           && return_type == return_normal
  5012.           && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  5013.                 | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED))))
  5014.         warn_about_return_type = 1;
  5015.       /* Save warning until we know what is really going on.  */
  5016.       type = integer_type_node;
  5017.     }
  5018.     }
  5019.   else if (return_type == return_dtor)
  5020.     {
  5021.       error ("return type specification for destructor invalid");
  5022.       type = void_type_node;
  5023.     }
  5024.   else if (return_type == return_ctor)
  5025.     {
  5026.       warning ("return type specification for constructor invalid");
  5027.       type = TYPE_POINTER_TO (ctor_return_type);
  5028.     }
  5029.  
  5030.   ctype = NULL_TREE;
  5031.  
  5032.   /* Now process the modifiers that were specified
  5033.      and check for invalid combinations.  */
  5034.  
  5035.   /* Long double is a special combination.  */
  5036.  
  5037.   if ((specbits & 1 << (int) RID_LONG) && type == double_type_node)
  5038.     {
  5039.       specbits &= ~ (1 << (int) RID_LONG);
  5040.       type = long_double_type_node;
  5041.     }
  5042.  
  5043.   /* Check all other uses of type modifiers.  */
  5044.  
  5045.   if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  5046.           | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
  5047.     {
  5048.       explicit_type = 1;
  5049.       if (!explicit_int && !explicit_char && !pedantic)
  5050.     error ("long, short, signed or unsigned used invalidly for `%s'", name);
  5051.       else if ((specbits & 1 << (int) RID_LONG) && (specbits & 1 << (int) RID_SHORT))
  5052.     error ("long and short specified together for `%s'", name);
  5053.       else if (((specbits & 1 << (int) RID_LONG) || (specbits & 1 << (int) RID_SHORT))
  5054.            && explicit_char)
  5055.     error ("long or short specified with char for `%s'", name);
  5056.       else if ((specbits & 1 << (int) RID_SIGNED) && (specbits & 1 << (int) RID_UNSIGNED))
  5057.     error ("signed and unsigned given together for `%s'", name);
  5058.       else
  5059.     {
  5060.       if (specbits & 1 << (int) RID_UNSIGNED)
  5061.         {
  5062.           if (longlong)
  5063.         type = long_long_unsigned_type_node;
  5064.           else if (specbits & 1 << (int) RID_LONG)
  5065.         type = long_unsigned_type_node;
  5066.           else if (specbits & 1 << (int) RID_SHORT)
  5067.         type = short_unsigned_type_node;
  5068.           else if (type == char_type_node)
  5069.         type = unsigned_char_type_node;
  5070.           else
  5071.         type = unsigned_type_node;
  5072.         }
  5073.       else if ((specbits & 1 << (int) RID_SIGNED)
  5074.            && type == char_type_node)
  5075.         type = signed_char_type_node;
  5076.       else if (longlong)
  5077.         type = long_long_integer_type_node;
  5078.       else if (specbits & 1 << (int) RID_LONG)
  5079.         type = long_integer_type_node;
  5080.       else if (specbits & 1 << (int) RID_SHORT)
  5081.         type = short_integer_type_node;
  5082.     }
  5083.     }
  5084.  
  5085.   /* Set CONSTP if this declaration is `const', whether by
  5086.      explicit specification or via a typedef.
  5087.      Likewise for VOLATILEP.  */
  5088.  
  5089.   constp = !! (specbits & 1 << (int) RID_CONST) + TREE_READONLY (type);
  5090.   volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TREE_VOLATILE (type);
  5091.   staticp = 0;
  5092.   inlinep = !! (specbits & (1 << (int) RID_INLINE));
  5093.   if (constp > 1)
  5094.     warning ("duplicate `const'");
  5095.   if (volatilep > 1)
  5096.     warning ("duplicate `volatile'");
  5097.   virtualp = specbits & (1 << (int) RID_VIRTUAL);
  5098.   if (specbits & (1 << (int) RID_STATIC))
  5099.     staticp = 1 + (decl_context == FIELD);
  5100.  
  5101.   if (virtualp && staticp == 2)
  5102.     {
  5103.       error ("member `%s' cannot be declared both virtual and static", name);
  5104.       staticp = 0;
  5105.     }
  5106.   friendp = specbits & (1 << (int) RID_FRIEND);
  5107.   specbits &= ~ ((1 << (int) RID_VIRTUAL) | (1 << (int) RID_FRIEND));
  5108.  
  5109.   /* Warn if two storage classes are given. Default to `auto'.  */
  5110.  
  5111.   if (specbits)
  5112.     {
  5113.       explicit_type = 1;
  5114.       if (specbits & 1 << (int) RID_STATIC) nclasses++;
  5115.       if (specbits & 1 << (int) RID_EXTERN) nclasses++;
  5116.       if (decl_context == PARM && nclasses > 0)
  5117.     error ("storage class specifiers invalid in parameter declarations");
  5118.       if (specbits & 1 << (int) RID_TYPEDEF)
  5119.     {
  5120.       if (decl_context == PARM)
  5121.         error ("typedef declaration invalid in parameter declaration");
  5122.       nclasses++;
  5123.     }
  5124.       if (specbits & 1 << (int) RID_AUTO) nclasses++;
  5125.       if (specbits & 1 << (int) RID_REGISTER) nclasses++;
  5126.     }
  5127.  
  5128.   /* Give error if `virtual' is used outside of class declaration.  */
  5129.   if (virtualp && current_class_name == NULL_TREE)
  5130.     {
  5131.       error ("virtual outside class declaration");
  5132.       virtualp = 0;
  5133.     }
  5134.  
  5135.   /* Warn about storage classes that are invalid for certain
  5136.      kinds of declarations (parameters, typenames, etc.).  */
  5137.  
  5138.   if (nclasses > 1)
  5139.     error ("multiple storage classes in declaration of `%s'", name);
  5140.   else if (decl_context != NORMAL && nclasses > 0)
  5141.     {
  5142.       if (decl_context == PARM && (specbits & ((1 << (int) RID_REGISTER)|(1 << (int) RID_AUTO))))
  5143.     ;
  5144.       else if (decl_context == FIELD
  5145.            && (specbits
  5146.            & (/* C++ allows static class elements  */
  5147.               (1 << (int) RID_STATIC)
  5148.               /* ...and inlines  */
  5149.               | (1 << (int) RID_INLINE)
  5150.               /* ...and signed and unsigned elements.  */
  5151.               | (1 << (int) RID_SIGNED)
  5152.               | (1 << (int) RID_UNSIGNED))))
  5153.     ;
  5154.       else if (decl_context == FIELD && (specbits & (1 << (int) RID_TYPEDEF)))
  5155.     {
  5156.       /* A typedef which was made in a class's scope.  */
  5157.       tree loc_typedecl;
  5158.       register int i = sizeof (struct lang_decl_flags) / sizeof (int);
  5159.       register int *pi;
  5160.  
  5161.       /* keep `grokdeclarator' from thinking we are in PARM context.  */
  5162.       pushlevel (0);
  5163.       loc_typedecl = start_decl (declarator, declspecs, initialized, NULL_TREE);
  5164.  
  5165.       pi = (int *) permalloc (sizeof (struct lang_decl_flags));
  5166.       while (i > 0)
  5167.         pi[--i] = 0;
  5168.       DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
  5169.       poplevel (0, 0, 0);
  5170.  
  5171.       if (TREE_CODE (TREE_TYPE (loc_typedecl)) == ENUMERAL_TYPE)
  5172.         {
  5173.           tree ref = lookup_tag (ENUMERAL_TYPE, DECL_NAME (loc_typedecl), current_binding_level, 0);
  5174.           if (! ref)
  5175.         pushtag (DECL_NAME (loc_typedecl), TREE_TYPE (loc_typedecl));
  5176.         }
  5177.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)))
  5178.         error_with_decl (loc_typedecl,
  5179.                  "typedef of `%s' in class scope hides previous declaration");
  5180. #if 0
  5181.       /* Must push this into scope via `pushdecl_class_level'.  */
  5182.       IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)) = loc_typedecl;
  5183. #endif
  5184.       return loc_typedecl;
  5185.     }
  5186.       else
  5187.     {
  5188.       error ((decl_context == FIELD
  5189.           ? "storage class specified for structure field `%s'"
  5190.           : (decl_context == PARM
  5191.              ? "storage class specified for parameter `%s'"
  5192.              : "storage class specified for typename")),
  5193.          name);
  5194.       specbits &= ~ ((1 << (int) RID_REGISTER) | (1 << (int) RID_AUTO)
  5195.              | (1 << (int) RID_EXTERN));
  5196.     }
  5197.     }
  5198.   else if (current_binding_level == global_binding_level)
  5199.     {
  5200.       if (specbits & (1 << (int) RID_AUTO))
  5201.     error ("top-level declaration of `%s' specifies `auto'", name);
  5202. #if 0
  5203.       if (specbits & (1 << (int) RID_REGISTER))
  5204.     error ("top-level declaration of `%s' specifies `register'", name);
  5205. #endif
  5206. #if 0
  5207.       /* I'm not sure under what circumstances we should turn
  5208.      on the extern bit, and under what circumstances we should
  5209.      warn if other bits are turned on.  */
  5210.       if (decl_context == NORMAL
  5211.       && (specbits & (1 << (int) RID_EXTERN)) == 0
  5212.       && ! root_lang_context_p ())
  5213.     {
  5214.       specbits |= (1 << (int) RID_EXTERN);
  5215.     }
  5216. #endif
  5217.     }
  5218.  
  5219.   /* Now figure out the structure of the declarator proper.
  5220.      Descend through it, creating more complex types, until we reach
  5221.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  5222.  
  5223.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  5224.     {
  5225.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  5226.      an INDIRECT_REF (for *...),
  5227.      a CALL_EXPR (for ...(...)),
  5228.      an identifier (for the name being declared)
  5229.      or a null pointer (for the place in an absolute declarator
  5230.      where the name was omitted).
  5231.      For the last two cases, we have just exited the loop.
  5232.  
  5233.      For C++ it could also be
  5234.      a SCOPE_REF (for class :: ...).  In this case, we have converted
  5235.      sensible names to types, and those are the values we use to
  5236.      qualify the member name.
  5237.      an ADDR_EXPR (for &...),
  5238.      a BIT_NOT_EXPR (for destructors)
  5239.      a TYPE_EXPR (for operator typenames)
  5240.      a WRAPPER_EXPR (for wrappers)
  5241.      an ANTI_WRAPPER_EXPR (for averting wrappers)
  5242.  
  5243.      At this point, TYPE is the type of elements of an array,
  5244.      or for a function to return, or for a pointer to point to.
  5245.      After this sequence of ifs, TYPE is the type of the
  5246.      array or function or pointer, and DECLARATOR has had its
  5247.      outermost layer removed.  */
  5248.  
  5249.       if (TREE_CODE (type) == ERROR_MARK
  5250.       && TREE_CODE (declarator) != OP_IDENTIFIER)
  5251.     {
  5252.       if (TREE_CODE (declarator) == SCOPE_REF)
  5253.         declarator = TREE_OPERAND (declarator, 1);
  5254.       else
  5255.         declarator = TREE_OPERAND (declarator, 0);
  5256.       continue;
  5257.     }
  5258.       if (quals != NULL_TREE
  5259.       && (declarator == NULL_TREE
  5260.           || TREE_CODE (declarator) != SCOPE_REF))
  5261.     {
  5262.       if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
  5263.         ctype = TYPE_METHOD_BASETYPE (type);
  5264.       if (ctype != NULL_TREE)
  5265.         {
  5266.           tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
  5267.           ctype = grok_method_quals (ctype, dummy, quals);
  5268.           type = TREE_TYPE (dummy);
  5269.           quals = NULL_TREE;
  5270.         }
  5271.     }
  5272.       switch (TREE_CODE (declarator))
  5273.     {
  5274.     case ARRAY_REF:
  5275.       {
  5276.         register tree itype = NULL_TREE;
  5277.         register tree size = TREE_OPERAND (declarator, 1);
  5278.  
  5279.         declarator = TREE_OPERAND (declarator, 0);
  5280.  
  5281.         /* Check for some types that there cannot be arrays of.  */
  5282.  
  5283.         if (type == void_type_node)
  5284.           {
  5285.         error ("declaration of `%s' as array of voids", name);
  5286.         type = error_mark_node;
  5287.           }
  5288.  
  5289.         if (TREE_CODE (type) == FUNCTION_TYPE)
  5290.           {
  5291.         error ("declaration of `%s' as array of functions", name);
  5292.         type = error_mark_node;
  5293.           }
  5294.  
  5295.         if (size == error_mark_node)
  5296.           type = error_mark_node;
  5297.  
  5298.         if (type == error_mark_node)
  5299.           continue;
  5300.  
  5301.         if (size)
  5302.           {
  5303.         /* Must suspend_momentary here because the index
  5304.            type may need to live until the end of the function.
  5305.            For example, it is used in the declaration of a
  5306.            variable which requires destructing at the end of
  5307.            the function; then build_vec_delete will need this
  5308.            value.  */
  5309.         int yes = suspend_momentary ();
  5310.         /* might be a cast */
  5311.         if (TREE_CODE (size) == NOP_EXPR
  5312.             && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  5313.           size = TREE_OPERAND (size, 0);
  5314.  
  5315.         if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  5316.             && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  5317.           {
  5318.             error ("size of array `%s' has non-integer type", name);
  5319.             size = integer_one_node;
  5320.           }
  5321.         if (TREE_READONLY_DECL_P (size))
  5322.           size = decl_constant_value (size);
  5323.         if (pedantic && integer_zerop (size))
  5324.           warning ("ANSI C forbids zero-size array `%s'", name);
  5325.         if (TREE_LITERAL (size))
  5326.           {
  5327.             if (INT_CST_LT (size, integer_zero_node))
  5328.               {
  5329.             error ("size of array `%s' is negative", name);
  5330.             size = integer_one_node;
  5331.               }
  5332.             itype = build_index_type (build_int_2 (TREE_INT_CST_LOW (size) - 1, 0));
  5333.           }
  5334.         else
  5335.           {
  5336.             if (pedantic)
  5337.               warning ("ANSI C forbids variable-size array `%s'", name);
  5338.             itype = build_binary_op (MINUS_EXPR, size, integer_one_node);
  5339.             itype = build_index_type (itype);
  5340.           }
  5341.         resume_momentary (yes);
  5342.           }
  5343.  
  5344.         /* Build the array type itself.
  5345.            Merge any constancy or volatility into the target type.  */
  5346.  
  5347.         if (constp || volatilep)
  5348.           type = build_type_variant (type, constp, volatilep);
  5349.  
  5350. #if 0   /* don't clear these; leave them set so that the array type
  5351.        or the variable is itself const or volatile.  */
  5352.         constp = 0;
  5353.         volatilep = 0;
  5354. #endif
  5355.  
  5356.         type = build_cplus_array_type (type, itype);
  5357.         ctype = NULL_TREE;
  5358.       }
  5359.       break;
  5360.  
  5361.     case CALL_EXPR:
  5362.       {
  5363.         tree arg_types;
  5364.  
  5365.         /* Declaring a function type.
  5366.            Make sure we have a valid type for the function to return.  */
  5367.         /* Is this an error?  Should they be merged into TYPE here?  */
  5368.         if (pedantic && (constp || volatilep))
  5369.           warning ("function declared to return const or volatile result");
  5370.  
  5371.         /* Warn about some types functions can't return.  */
  5372.  
  5373.         if (TREE_CODE (type) == FUNCTION_TYPE)
  5374.           {
  5375.         error ("`%s' declared as function returning a function", name);
  5376.         type = integer_type_node;
  5377.           }
  5378.         if (TREE_CODE (type) == ARRAY_TYPE)
  5379.           {
  5380.         error ("`%s' declared as function returning an array", name);
  5381.         type = integer_type_node;
  5382.           }
  5383.  
  5384.         if (ctype == NULL_TREE
  5385.         && decl_context == FIELD
  5386.         && (friendp == 0 || dname == current_class_name))
  5387.           ctype = current_class_type;
  5388.  
  5389.         if (ctype && flags == TYPENAME_FLAG)
  5390.           TYPE_HAS_CONVERSION (ctype) = 1;
  5391.         if (ctype && DECL_NAME (TYPE_NAME (ctype)) == dname)
  5392.           {
  5393.         /* We are within a class's scope. If our declarator name
  5394.            is the same as the class name, and we are defining
  5395.            a function, then it is a constructor/destructor, and
  5396.            therefore returns a void type.  */
  5397.  
  5398.         if (flags == DTOR_FLAG)
  5399.           {
  5400.             if (staticp == 2)
  5401.               error ("destructor cannot be static member function");
  5402.             if (decl_context == FIELD)
  5403.               {
  5404.             if (! member_function_or_else (ctype, current_class_type,
  5405.                                "destructor for alien class `%s' cannot be a member"))
  5406.               return NULL_TREE;
  5407.             if (TYPE_HAS_DESTRUCTOR (ctype))
  5408.               error_with_aggr_type (ctype, "class `%s' already has destructor defined");
  5409.               }
  5410.           }
  5411.         else if (flags == WRAPPER_FLAG || flags == ANTI_WRAPPER_FLAG)
  5412.           {
  5413.             if (staticp == 2)
  5414.               error ("wrapper cannot be static member function");
  5415.             if (decl_context == FIELD)
  5416.               {
  5417.             if (! member_function_or_else (ctype, current_class_type,
  5418.                                "wrapper for alien class `%s' cannot be member"))
  5419.               return NULL_TREE;
  5420.             TYPE_WRAP_TYPE (ctype) = TYPE_MAIN_VARIANT (ctype);
  5421.               }
  5422.           }
  5423.         else if (flags == WRAPPER_PRED_FLAG)
  5424.           {
  5425.             if (staticp == 2)
  5426.               error ("wrapper predicate cannot be static member function");
  5427.             if (TREE_CODE (type) != INTEGER_TYPE)
  5428.               {
  5429.             error ("wrapper predicated must return an integer type");
  5430.             type = integer_type_node;
  5431.               }
  5432.             if (decl_context == FIELD)
  5433.               {
  5434.             if (! member_function_or_else (ctype, current_class_type,
  5435.                                "wrapper predicate for alien class `%s' cannot be member"))
  5436.               return NULL_TREE;
  5437.             TYPE_HAS_WRAPPER_PRED (ctype) = 1;
  5438.               }
  5439.           }
  5440.         else            /* its a constructor. */
  5441.           {
  5442.             if (staticp == 2)
  5443.               error ("constructor cannot be static member function");
  5444.             if (virtualp || friendp)
  5445.               {
  5446.             error ("constructors cannot be declared virtual or friend");
  5447.             virtualp = 0;
  5448.             friendp = 0;
  5449.               }
  5450.             if (specbits & ~((1 << (int) RID_INLINE)|(1 << (int) RID_STATIC)))
  5451.               error ("return value type specifier for `%s' ignored",
  5452.                  flags == DTOR_FLAG ? "destructor" : "constructor");
  5453.             type = TYPE_POINTER_TO (ctype);
  5454.             if (decl_context == FIELD)
  5455.               {
  5456.             if (! member_function_or_else (ctype, current_class_type,
  5457.                                "constructor for alien class `%s' cannot be member"))
  5458.               return NULL_TREE;
  5459.             TYPE_HAS_CONSTRUCTOR (ctype) = 1;
  5460.             assert (return_type == return_ctor);
  5461.               }
  5462.           }
  5463.         if (decl_context == FIELD)
  5464.           staticp = 0;
  5465.           }
  5466.         else if (friendp && virtualp)
  5467.           {
  5468.         /* Cannot be both friend and virtual.  */
  5469.         error ("virtual functions cannot be friends");
  5470.         specbits ^= (1 << (int) RID_FRIEND);
  5471.           }
  5472.  
  5473.         if (decl_context == NORMAL && friendp)
  5474.           error ("friend declaration not in class definition");
  5475.  
  5476.         /* Picky up type qualifiers which should be applied to `this'.  */
  5477.         quals = TREE_OPERAND (declarator, 2);
  5478.  
  5479.         /* Traditionally, declaring return type float means double.  */
  5480.  
  5481.         if (flag_traditional && type == float_type_node)
  5482.           type = double_type_node;
  5483.  
  5484.         /* Construct the function type and go to the next
  5485.            inner layer of declarator.  */
  5486.  
  5487.         {
  5488.           int funcdef_p;
  5489.           tree inner_parms = TREE_OPERAND (declarator, 1);
  5490.           tree inner_decl = TREE_OPERAND (declarator, 0);
  5491.  
  5492.           declarator = TREE_OPERAND (declarator, 0);
  5493.  
  5494.           if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
  5495.         inner_decl = TREE_OPERAND (inner_decl, 1);
  5496.  
  5497.           /* Say it's a definition only for the CALL_EXPR
  5498.          closest to the identifier.  */
  5499.           funcdef_p =
  5500.         (inner_decl &&
  5501.          (TREE_CODE (inner_decl) == IDENTIFIER_NODE
  5502.           || TREE_CODE (inner_decl) == OP_IDENTIFIER
  5503.           || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0;
  5504.  
  5505.           arg_types = grokparms (inner_parms, funcdef_p);
  5506.         }
  5507.  
  5508.         if (declarator)
  5509.           {
  5510.         /* Get past destructors, wrappers, etc.
  5511.            We know we have one because FLAGS will be non-zero.
  5512.  
  5513.            Complain about improper parameter lists here.  */
  5514.         if (TREE_CODE (declarator) == BIT_NOT_EXPR)
  5515.           {
  5516.             declarator = TREE_OPERAND (declarator, 0);
  5517.  
  5518.             if (strict_prototype == 0 && arg_types == NULL_TREE)
  5519.               arg_types = void_list_node;
  5520.             else if (arg_types == NULL_TREE
  5521.                  || arg_types != void_list_node)
  5522.               {
  5523.             error ("destructors cannot be specified with parameters");
  5524.             arg_types = void_list_node;
  5525.               }
  5526.           }
  5527.         else if (TREE_CODE (declarator) == WRAPPER_EXPR)
  5528.           {
  5529.             /* Report misuse of wrappers and their associates.
  5530.                Note that because wrappers may be invoked
  5531.                quite a bit implicitly, if we give an error
  5532.                message, we make an effort to fix that error
  5533.                so that spurious errors do not show up.  */
  5534.             if (TREE_CODE (TREE_OPERAND (declarator, 0)) == COND_EXPR)
  5535.               {
  5536.             /* First parameter must be a pointer to a member function.
  5537.                Rest of parameters must all be default parameters.  */
  5538.             if (arg_types == NULL_TREE
  5539.                 || arg_types == void_list_node
  5540.                 || TREE_CODE (TREE_VALUE (arg_types)) != POINTER_TYPE
  5541.                 || TREE_CODE (TREE_TYPE (TREE_VALUE (arg_types))) != METHOD_TYPE)
  5542.               {
  5543.                 error ("wrapper predicate takes a pointer-to-member-function as first argument");
  5544.                 arg_types = NULL_TREE;
  5545.               }
  5546.             else if (TREE_CHAIN (arg_types)
  5547.                  && TREE_CHAIN (arg_types) != void_list_node
  5548.                  && TREE_PURPOSE (TREE_CHAIN (arg_types)) == NULL_TREE)
  5549.               {
  5550.                 error ("all arguments past first must be default for wrapper predicate");
  5551.                 TREE_CHAIN (arg_types) = NULL_TREE;
  5552.               }
  5553.             declarator = wrapper_pred_name;
  5554.               }
  5555.             else
  5556.               {
  5557.             /* First parameter must be an int.
  5558.                Second parameter must be a pointer to a member function.  */
  5559.             if (arg_types == NULL_TREE || TREE_CHAIN (arg_types) == NULL_TREE)
  5560.               {
  5561.                 error ("wrappers must have at least two arguments (int, pointer-to-member-function)");
  5562.                 arg_types = NULL_TREE;
  5563.               }
  5564.             else
  5565.               {
  5566.                 if (TREE_CODE (TREE_VALUE (arg_types)) != INTEGER_TYPE)
  5567.                   {
  5568.                 error ("first argument to wrapper must be an integer");
  5569.                 TREE_VALUE (arg_types) = integer_type_node;
  5570.                   }
  5571.                 if (TREE_CODE (TREE_VALUE (TREE_CHAIN (arg_types))) != POINTER_TYPE
  5572.                 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arg_types)))) != METHOD_TYPE)
  5573.                   {
  5574.                 error ("second argument to wrapper must be a pointer-to-member-function type");
  5575.                 TREE_CHAIN (arg_types) = NULL_TREE;
  5576.                   }
  5577.               }
  5578.             declarator = wrapper_name;
  5579.               }
  5580.           }
  5581.         else if (TREE_CODE (declarator) == ANTI_WRAPPER_EXPR)
  5582.           declarator = anti_wrapper_name;
  5583.           }
  5584.  
  5585.         type = build_function_type (type, flag_traditional ? 0 : arg_types);
  5586.       }
  5587.       break;
  5588.  
  5589.     case ADDR_EXPR:
  5590.     case INDIRECT_REF:
  5591.       /* Filter out pointers-to-references and references-to-references.
  5592.          We can get these if a TYPE_DECL is used.  */
  5593.  
  5594.       if (TREE_CODE (type) == REFERENCE_TYPE)
  5595.         {
  5596.           error ("cannot declare %s to references",
  5597.              TREE_CODE (declarator) == ADDR_EXPR
  5598.              ? "references" : "pointers");
  5599.           declarator = TREE_OPERAND (declarator, 0);
  5600.           continue;
  5601.         }
  5602.  
  5603.       /* Merge any constancy or volatility into the target type
  5604.          for the pointer.  */
  5605.  
  5606.       if (constp || volatilep)
  5607.         {
  5608.           type = build_type_variant (type, constp, volatilep);
  5609.           if (IS_AGGR_TYPE (type))
  5610.         build_pointer_type (type);
  5611.         }
  5612.       constp = 0;
  5613.       volatilep = 0;
  5614.  
  5615.       if (TREE_CODE (declarator) == ADDR_EXPR)
  5616.         if (TREE_CODE (type) == FUNCTION_TYPE)
  5617.           {
  5618.         error ("cannot declare references to functions; use pointer to function instead");
  5619.         type = build_pointer_type (type);
  5620.           }
  5621.         else
  5622.           {
  5623.         if (TYPE_MAIN_VARIANT (type) == void_type_node)
  5624.           error ("invalid type: `void &'");
  5625.         else
  5626.           type = build_reference_type (type);
  5627.           }
  5628.       else
  5629.         type = build_pointer_type (type);
  5630.  
  5631.       /* Process a list of type modifier keywords (such as
  5632.          const or volatile) that were given inside the `*' or `&'.  */
  5633.  
  5634.       if (TREE_TYPE (declarator))
  5635.         {
  5636.           register tree typemodlist;
  5637.           int erred = 0;
  5638.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  5639.            typemodlist = TREE_CHAIN (typemodlist))
  5640.         {
  5641.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  5642.             constp++;
  5643.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  5644.             volatilep++;
  5645.           else if (!erred)
  5646.             {
  5647.               erred = 1;
  5648.               error ("invalid type modifier within %s declarator",
  5649.                  TREE_CODE (declarator) == ADDR_EXPR
  5650.                  ? "reference" : "pointer");
  5651.             }
  5652.         }
  5653.           if (constp > 1)
  5654.         warning ("duplicate `const'");
  5655.           if (volatilep > 1)
  5656.         warning ("duplicate `volatile'");
  5657.         }
  5658.       declarator = TREE_OPERAND (declarator, 0);
  5659.       ctype = NULL_TREE;
  5660.       break;
  5661.  
  5662.     case SCOPE_REF:
  5663.       {
  5664.         /* We have converted type names to NULL_TREE if the
  5665.            name was bogus, or to a _TYPE node, if not.
  5666.  
  5667.            The variable CTYPE holds the type we will ultimately
  5668.            resolve to.  The code here just needs to build
  5669.            up appropriate member types.  */
  5670.         tree sname = TREE_OPERAND (declarator, 1);
  5671.  
  5672.         if (TREE_OPERAND (declarator, 0) == NULL_TREE)
  5673.           {
  5674.         /* We had a reference to a global decl, or
  5675.            perhaps we were given a non-aggregate typedef,
  5676.            in which case we cleared this out, and should just
  5677.            keep going as though it wasn't there.  */
  5678.         declarator = sname;
  5679.         continue;
  5680.           }
  5681.         ctype = TREE_OPERAND (declarator, 0);
  5682.  
  5683.         if (sname == NULL_TREE)
  5684.           goto done_scoping;
  5685.  
  5686.         /* Destructors can have their visibilities changed as well.  */
  5687.         if (TREE_CODE (sname) == BIT_NOT_EXPR)
  5688.           sname = TREE_OPERAND (sname, 0);
  5689.  
  5690.         if (TREE_CODE (sname) == IDENTIFIER_NODE)
  5691.           {
  5692.         /* This is the `standard' use of the scoping operator:
  5693.            basetype :: member .  */
  5694.  
  5695.         if (ctype == current_class_type || friendp)
  5696.           if (TREE_CODE (type) == FUNCTION_TYPE)
  5697.             type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  5698.           else
  5699.             type = build_member_type (ctype, type);
  5700.         else if (TYPE_SIZE (ctype) != 0
  5701.             || (specbits & (1<<(int)RID_TYPEDEF)))
  5702.           {
  5703.             tree t;
  5704.             /* have to move this code elsewhere in this function.
  5705.                this code is used for i.e., typedef int A::M; M *pm; */
  5706.  
  5707.             if (decl_context == FIELD)
  5708.               {
  5709.             t = lookup_field (ctype, sname, 0);
  5710.             if (t)
  5711.               {
  5712.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  5713.                 DECL_INITIAL (t) = init;
  5714.                 return t;
  5715.               }
  5716.             /* No such field, try member functions.  */
  5717.             t = lookup_fnfields (CLASSTYPE_AS_LIST (ctype), sname, 0);
  5718.             if (t)
  5719.               {
  5720.                 if (flags == DTOR_FLAG)
  5721.                   t = TREE_VALUE (t);
  5722.                 else if (CLASSTYPE_METHOD_VEC (ctype)
  5723.                      && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
  5724.                   {
  5725.                 /* Don't include destructor with constructors.  */
  5726.                 t = TREE_CHAIN (TREE_VALUE (t));
  5727.                 if (t == NULL_TREE)
  5728.                   error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
  5729.                 t = build_tree_list (NULL_TREE, t);
  5730.                   }
  5731.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  5732.                 DECL_INITIAL (t) = init;
  5733.                 return t;
  5734.               }
  5735.  
  5736.             if (flags == TYPENAME_FLAG)
  5737.               error_with_aggr_type (ctype, "type conversion is not a member of structure `%s'");
  5738.             else
  5739.               error ("field `%s' is not a member of structure `%s'",
  5740.                  IDENTIFIER_POINTER (sname),
  5741.                  TYPE_NAME_STRING (ctype));
  5742.               }
  5743.             if (TREE_CODE (type) == FUNCTION_TYPE)
  5744.               type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  5745.             else
  5746.               type = build_member_type (ctype, type);
  5747.           }
  5748.         else
  5749.           sorry ("structure `%s' not yet defined",
  5750.              TYPE_NAME_STRING (ctype));
  5751.         declarator = sname;
  5752.           }
  5753.         else if (TREE_CODE (sname) == TYPE_EXPR)
  5754.           {
  5755.         /* A TYPE_EXPR will change types out from under us.
  5756.            So do the TYPE_EXPR now, and make this SCOPE_REF
  5757.            inner to the TYPE_EXPR's CALL_EXPR.
  5758.  
  5759.            This does not work if we don't get a CALL_EXPR back.
  5760.            I did not think about error recovery, hence the
  5761.            assert (0).  */
  5762.  
  5763.         /* Get the CALL_EXPR.  */
  5764.         sname = grokoptypename (sname, 0);
  5765.         assert (TREE_CODE (sname) == CALL_EXPR);
  5766.         type = TREE_TYPE (TREE_OPERAND (sname, 0));
  5767.         /* Scope the CALL_EXPR's name.  */
  5768.         TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0);
  5769.         /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position.  */
  5770.         TREE_OPERAND (sname, 0) = declarator;
  5771.         /* Now work from the CALL_EXPR.  */
  5772.         declarator = sname;
  5773.         continue;
  5774.           }
  5775.         else if (TREE_CODE (sname) == SCOPE_REF)
  5776.           abort ();
  5777.         else
  5778.           {
  5779.           done_scoping:
  5780.         declarator = TREE_OPERAND (declarator, 1);
  5781.         if (declarator && TREE_CODE (declarator) == CALL_EXPR)
  5782.           /* In this case, we will deal with it later.  */
  5783.           ;
  5784.         else
  5785.           {
  5786.             if (TREE_CODE (type) == FUNCTION_TYPE)
  5787.               type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  5788.             else
  5789.               type = build_member_type (ctype, type);
  5790.           }
  5791.           }
  5792.       }
  5793.       break;
  5794.  
  5795.     case OP_IDENTIFIER:
  5796.       /* This is exceptional, in that we must finalize a 
  5797.          member type before calling grokopexpr, if we want
  5798.          to use the declared type information to resolve
  5799.          ambiguities.  Do not get fooled by friends,
  5800.          which do not have a member type built for them
  5801.          unless they were explicitly scoped (in which case that
  5802.          will have been taken care of in the SCOPE_REF case.  */
  5803.       if (TREE_CODE (type) != FUNCTION_TYPE
  5804.           && TREE_CODE (type) != METHOD_TYPE)
  5805.         {
  5806.           error ("operator name missing at this point in file");
  5807.           if (ctype)
  5808.         type = build_cplus_method_type (ctype, type, NULL_TREE);
  5809.           else
  5810.         type = build_function_type (type, NULL_TREE);
  5811.         }
  5812.       if (TREE_CODE (TREE_OPERAND (declarator, 0)) == NEW_EXPR)
  5813.         {
  5814.           int was_method = ctype || TREE_CODE (type) == METHOD_TYPE;
  5815.           type = coerce_new_type (ctype, type);
  5816.           if (was_method)
  5817.         staticp = 2;
  5818.         }
  5819.       else if (TREE_CODE (TREE_OPERAND (declarator, 0)) == DELETE_EXPR)
  5820.         {
  5821.           int was_method = ctype || TREE_CODE (type) == METHOD_TYPE;
  5822.           type = coerce_delete_type (ctype, type);
  5823.           if (was_method)
  5824.         staticp = 2;
  5825.         }
  5826.       else if (TREE_CODE (type) == FUNCTION_TYPE
  5827.            && ctype != 0
  5828.            && (friendp == 0 || staticp < 2))
  5829.         type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  5830.       {
  5831.         tree tmp = declarator;
  5832.         declarator = grokopexpr (&tmp, ctype, type, 0,
  5833.                      staticp == 2 ? 2 : 1);
  5834.       }
  5835.       if (declarator == NULL_TREE)
  5836.         return NULL_TREE;
  5837.       name = IDENTIFIER_POINTER (declarator);
  5838.       break;
  5839.  
  5840.     case BIT_NOT_EXPR:
  5841.       declarator = TREE_OPERAND (declarator, 0);
  5842.       break;
  5843.  
  5844.     case TYPE_EXPR:
  5845.       declarator = grokoptypename (declarator, 0);
  5846.       if (explicit_int != -1)
  5847.         if (comp_target_types (type, TREE_TYPE (TREE_OPERAND (declarator, 0)), 1) == 0)
  5848.           error ("type conversion function declared to return incongruent type");
  5849.         else
  5850.           warning ("return type specified for type conversion function");
  5851.       type = TREE_TYPE (TREE_OPERAND (declarator, 0));
  5852.       break;
  5853.  
  5854.     case WRAPPER_EXPR:
  5855.       if (TREE_CODE (TREE_OPERAND (declarator, 0)) == COND_EXPR)
  5856.         declarator = wrapper_pred_name;
  5857.       else
  5858.         declarator = wrapper_name;
  5859.       break;
  5860.  
  5861.     case ANTI_WRAPPER_EXPR:
  5862.       declarator = anti_wrapper_name;
  5863.       break;
  5864.  
  5865.     case RECORD_TYPE:
  5866.     case UNION_TYPE:
  5867.     case ENUMERAL_TYPE:
  5868.       declarator = 0;
  5869.       break;
  5870.  
  5871.     case ERROR_MARK:
  5872.       declarator = 0;
  5873.       break;
  5874.  
  5875.     default:
  5876.       assert (0);
  5877.     }
  5878.  
  5879.       /* layout_type (type); */
  5880. #if 0
  5881.       /* @@ Should perhaps replace the following code by changes in
  5882.        * @@ stor_layout.c. */
  5883.       if (TREE_CODE (type) == FUNCTION_DECL)
  5884.     {
  5885.       /* A function variable in C should be Pmode rather than EPmode
  5886.          because it has just the address of a function, no static chain.*/
  5887.       TYPE_MODE (type) = Pmode;
  5888.     }
  5889. #endif
  5890.     }
  5891.  
  5892.   /* Now TYPE has the actual type.  */
  5893.  
  5894.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  5895.  
  5896.   if (specbits & (1 << (int) RID_TYPEDEF))
  5897.     {
  5898.       tree decl;
  5899.  
  5900.       /* Note that the grammar rejects storage classes
  5901.      in typenames, fields or parameters.  */
  5902.       if (constp || volatilep)
  5903.     type = build_type_variant (type, constp, volatilep);
  5904.  
  5905.       /* If the user declares "struct {...} foo" then `foo' will have
  5906.      an anonymous name.  Fill that name in now.  Nothing can
  5907.      refer to it, so nothing needs know about the name change.
  5908.      The TYPE_NAME field was filled in by build_struct_xref.  */
  5909.       if (TYPE_NAME (type)
  5910. #ifndef BREAK_C_TAGS
  5911.       && current_lang_name == lang_name_cplusplus
  5912. #endif
  5913.       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  5914.       && ANON_AGGRNAME_P (DECL_NAME (TYPE_NAME (type))))
  5915.     {
  5916.       /* replace the anonymous name with the real name everywhere.  */
  5917.       lookup_tag_reverse (type, declarator);
  5918.       DECL_NAME (TYPE_NAME (type)) = declarator;
  5919.  
  5920.       /* Replace names of default constructors and/or destructors.  */
  5921.       if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_METHOD_VEC (type))
  5922.         {
  5923.           tree method_vec = CLASSTYPE_METHOD_VEC (type);
  5924.           tree fnptr = TREE_VEC_ELT (method_vec, 0);
  5925.           while (fnptr)
  5926.         {
  5927.           DECL_ORIGINAL_NAME (fnptr) = declarator;
  5928.           fnptr = TREE_CHAIN  (fnptr);
  5929.         }
  5930.         }
  5931.     }
  5932.  
  5933.       decl = build_decl (TYPE_DECL, declarator, type);
  5934.       if (quals)
  5935.     {
  5936.       if (ctype == NULL_TREE)
  5937.         {
  5938.           assert (TREE_CODE (type) == METHOD_TYPE);
  5939.           ctype = TYPE_METHOD_BASETYPE (type);
  5940.         }
  5941.       grok_method_quals (ctype, decl, quals);
  5942.     }
  5943.  
  5944.       if (resume_temporary)
  5945.     resume_temporary_allocation ();
  5946.       return decl;
  5947.     }
  5948.  
  5949.   /* Detect the case of an array type of unspecified size
  5950.      which came, as such, direct from a typedef name.
  5951.      We must copy the type, so that each identifier gets
  5952.      a distinct type, so that each identifier's size can be
  5953.      controlled separately by its own initializer.  */
  5954.  
  5955.   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
  5956.       && TYPE_DOMAIN (type) == 0)
  5957.     {
  5958.       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
  5959.     }
  5960.  
  5961.   /* If this is a type name (such as, in a cast or sizeof),
  5962.      compute the type and return it now.  */
  5963.  
  5964.   if (decl_context == TYPENAME)
  5965.     {
  5966.       /* Note that the grammar rejects storage classes
  5967.      in typenames, fields or parameters.  */
  5968.       if (constp || volatilep)
  5969.     type = build_type_variant (type, constp, volatilep);
  5970.  
  5971.       /* Special case: "friend class foo" looks like a TYPENAME context.  */
  5972.       if (friendp)
  5973.     {
  5974.       /* A friendly class?  */
  5975.       make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
  5976.       type = void_type_node;
  5977.     }
  5978.       else if (quals)
  5979.     {
  5980.       tree dummy = build_decl (TYPE_DECL, declarator, type);
  5981.       if (ctype == NULL_TREE)
  5982.         {
  5983.           assert (TREE_CODE (type) == METHOD_TYPE);
  5984.           ctype = TYPE_METHOD_BASETYPE (type);
  5985.         }
  5986.       grok_method_quals (ctype, dummy, quals);
  5987.       type = TREE_TYPE (dummy);
  5988.     }
  5989.  
  5990.       if (resume_temporary)
  5991.     resume_temporary_allocation ();
  5992.       return type;
  5993.     }
  5994.  
  5995.   /* `void' at top level (not within pointer)
  5996.      is allowed only in typedefs or type names.
  5997.      We don't complain about parms either, but that is because
  5998.      a better error message can be made later.  */
  5999.  
  6000.   if (type == void_type_node && decl_context != PARM)
  6001.     {
  6002.       if (declarator != NULL_TREE
  6003.       && TREE_CODE (declarator) == IDENTIFIER_NODE)
  6004.     error ("variable or field `%s' declared void", name);
  6005.       else
  6006.     error ("variable or field declared void");
  6007.       type = integer_type_node;
  6008.     }
  6009.  
  6010.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  6011.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  6012.  
  6013.   {
  6014.     register tree decl;
  6015.  
  6016.     if (decl_context == PARM)
  6017.       {
  6018.     if (ctype)
  6019.       error ("cannot use `::' in parameter declaration");
  6020.     if (virtualp)
  6021.       error ("parameter declared `virtual'");
  6022.     if (quals)
  6023.       error ("`const' and `volatile' function specifiers invalid in parameter declaration");
  6024.     if (friendp)
  6025.       error ("invalid friend declaration");
  6026.     if (raises)
  6027.       error ("invalid raises declaration");
  6028.  
  6029.     /* A parameter declared as an array of T is really a pointer to T.
  6030.        One declared as a function is really a pointer to a function.
  6031.        One declared as a member is really a pointer to member.  */
  6032.  
  6033.     if (TREE_CODE (type) == ARRAY_TYPE)
  6034.       {
  6035.         /* Transfer const-ness of array into that of type pointed to.  */
  6036.         type = build_pointer_type
  6037.             (build_type_variant (TREE_TYPE (type), constp, volatilep));
  6038.         volatilep = constp = 0;
  6039.       }
  6040.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  6041.       type = build_pointer_type (type);
  6042.     else if (TREE_CODE (type) == OFFSET_TYPE)
  6043.       type = build_pointer_type (type);
  6044.  
  6045.     decl = build_decl (PARM_DECL, declarator, type);
  6046.  
  6047.     /* Compute the type actually passed in the parmlist,
  6048.        for the case where there is no prototype.
  6049.        (For example, shorts and chars are passed as ints.)
  6050.        When there is a prototype, this is overridden later.  */
  6051.  
  6052.     DECL_ARG_TYPE (decl) = type;
  6053.     if (type == float_type_node)
  6054.       DECL_ARG_TYPE (decl) = double_type_node;
  6055.     else if (TREE_CODE (type) == INTEGER_TYPE
  6056.          && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  6057.       DECL_ARG_TYPE (decl) = integer_type_node;
  6058.       }
  6059.     else if (decl_context == FIELD)
  6060.       {
  6061.     if (type == error_mark_node)
  6062.       {
  6063.         /* Happens when declaring arrays of sizes which
  6064.            are error_mark_node, for example.  */
  6065.         decl = NULL_TREE;
  6066.       }
  6067.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  6068.       {
  6069.         if (current_lang_name == lang_name_c)
  6070.           {
  6071.         error ("field `%s' declared as a function in %s language context",
  6072.                name, IDENTIFIER_POINTER (current_lang_name));
  6073.         type = build_pointer_type (type);
  6074.           }
  6075.         else
  6076.           {
  6077.         if (friendp == 0)
  6078.           {
  6079.             if (ctype == NULL_TREE)
  6080.               ctype = current_class_type;
  6081.             if (staticp < 2)
  6082.               type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  6083.           }
  6084.         decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
  6085.         TREE_INLINE (decl) = inlinep;
  6086.         if (specbits & (1 << (int) RID_EXTERN))
  6087.           TREE_PUBLIC (decl) = 1;
  6088.           }
  6089.       }
  6090.     else if (TREE_CODE (type) == METHOD_TYPE)
  6091.       {
  6092.         decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
  6093.         TREE_INLINE (decl) = inlinep;
  6094.         if (specbits & (1 << (int) RID_EXTERN))
  6095.           TREE_PUBLIC (decl) = 1;
  6096.       }
  6097.     else if (TREE_CODE (type) == RECORD_TYPE
  6098.          && CLASSTYPE_DECLARED_EXCEPTION (type))
  6099.       {
  6100.         /* Handle a class-local exception declaration.  */
  6101.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  6102.         if (ctype == NULL_TREE)
  6103.           ctype = current_class_type;
  6104.         finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  6105.                    ? DECL_NAME (TYPE_NAME (ctype)) : TYPE_NAME (ctype), decl);
  6106.         return void_type_node;
  6107.       }
  6108.     else if (TYPE_SIZE (type) == 0 && !staticp
  6109.          && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
  6110.       {
  6111.         if (declarator)
  6112.           error ("field `%s' has incomplete type",
  6113.              IDENTIFIER_POINTER (declarator));
  6114.         else
  6115.           error ("field has incomplete type");
  6116.         type = error_mark_node;
  6117.         decl = NULL_TREE;
  6118.       }
  6119.     else
  6120.       {
  6121.         if (friendp)
  6122.           {
  6123.         if (declarator)
  6124.           error ("`%s' is neither function nor method; cannot be declared friend",
  6125.              IDENTIFIER_POINTER (declarator));
  6126.         else
  6127.           {
  6128.             error ("invalid friend declaration");
  6129.             return void_type_node;
  6130.           }
  6131.         friendp = 0;
  6132.           }
  6133.         decl = NULL_TREE;
  6134.       }
  6135.  
  6136.     if (friendp)
  6137.       {
  6138.         /* Friends are treated specially.  */
  6139.         if (ctype == current_class_type)
  6140.           warning ("member functions are implicitly friends of their class");
  6141.         else if (DECL_NAME (decl))
  6142.           return do_friend (ctype, declarator, decl, last_function_parms, flags, quals);
  6143.         else return void_type_node;
  6144.       }
  6145.  
  6146.     /* Structure field.  It may not be a function, except for C++ */
  6147.  
  6148.     if (decl == 0)
  6149.       {
  6150.         if (virtualp)
  6151.           error ("field declared `virtual'");
  6152.         if (quals)
  6153.           error ("`const' and `volatile' function specifiers invalid in field declaration");
  6154.         if (friendp)
  6155.           error ("invalid friend declaration");
  6156.         if (raises)
  6157.           error ("invalid raises declaration");
  6158.  
  6159.         if (staticp || (constp && initialized))
  6160.           {
  6161.         /* C++ allows static class members.
  6162.            All other work for this is done by grokfield.
  6163.            This VAR_DECL is built by build_lang_field_decl.
  6164.            All other VAR_DECLs are built by build_decl.  */
  6165.         if (current_lang_name == lang_name_c)
  6166.           {
  6167.             if (staticp)
  6168.               error ("field `%s' declared static in %s language context",
  6169.                  name, IDENTIFIER_POINTER (current_lang_name));
  6170.             else
  6171.               error ("field `%s' declared with initializer in %s language context",
  6172.                  name, IDENTIFIER_POINTER (current_lang_name));
  6173.           }
  6174.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  6175.         if (staticp)
  6176.           TREE_STATIC (decl) = 1;
  6177.         /* In class context, static means public visibility.  */
  6178.         TREE_PUBLIC (decl) = 1;
  6179.           }
  6180.         else
  6181.           decl = build_lang_field_decl (FIELD_DECL, declarator, type);
  6182.       }
  6183.       }
  6184.     else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
  6185.       {
  6186.     int was_overloaded = 0;
  6187.     tree original_name = declarator;
  6188.  
  6189.     if (! declarator) return NULL_TREE;
  6190.  
  6191.     if (specbits & ((1 << (int) RID_AUTO) | (1 << (int) RID_REGISTER)))
  6192.       error ("invalid storage class for function `%s'", name);
  6193.     /* Function declaration not at top level.
  6194.        Storage classes other than `extern' are not allowed
  6195.        and `extern' makes no difference.  */
  6196.     if (current_binding_level != global_binding_level
  6197.         && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
  6198.         && pedantic)
  6199.       warning ("invalid storage class for function `%s'", name);
  6200.  
  6201.     if (ctype == NULL_TREE)
  6202.       {
  6203.         if (virtualp)
  6204.           {
  6205.         error ("virtual non-class function `%s'", name);
  6206.         virtualp = 0;
  6207.           }
  6208. #ifdef NO_AUTO_OVERLOAD
  6209.         if (is_overloaded (declarator))
  6210.           {
  6211.         /* Plain overloading: will not be grok'd by grokclassfn.  */
  6212.         if (current_lang_name == lang_name_cplusplus)
  6213.           declarator = build_decl_overload (name, TYPE_ARG_TYPES (type), 0);
  6214.         was_overloaded = 1;
  6215.           }
  6216. #else
  6217.         if (current_lang_name == lang_name_cplusplus
  6218.         && ! (IDENTIFIER_LENGTH (original_name) == 4
  6219.               && IDENTIFIER_POINTER (original_name)[0] == 'm'
  6220.               && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
  6221.         && ! (IDENTIFIER_LENGTH (original_name) > 10
  6222.               && IDENTIFIER_POINTER (original_name)[0] == '_'
  6223.               && IDENTIFIER_POINTER (original_name)[1] == '_'
  6224.               && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
  6225.           {
  6226.         /* Plain overloading: will not be grok'd by grokclassfn.  */
  6227.         declarator = build_decl_overload (name, TYPE_ARG_TYPES (type), 0);
  6228.         was_overloaded = 1;
  6229.           }
  6230. #endif
  6231.       }
  6232.     else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
  6233.       type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  6234.  
  6235.     decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? 2 : 1);
  6236.     /* Record presence of `static'.  In C++, `inline' is like `static'.  */
  6237.     TREE_PUBLIC (decl) = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)));
  6238.     /* Record presence of `inline', if it is reasonable.  */
  6239.     if (inlinep)
  6240.       {
  6241.         tree last = tree_last (TYPE_ARG_TYPES (type));
  6242.  
  6243.         if (! was_overloaded
  6244.         && ! ctype
  6245.         && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
  6246.           warning ("cannot inline function `main'");
  6247.         else if (last && last != void_list_node)
  6248.           warning ("inline declaration ignored for function with `...'");
  6249.         else
  6250.           /* Assume that otherwise the function can be inlined.  */
  6251.           TREE_INLINE (decl) = 1;
  6252.  
  6253.         if (specbits & (1 << (int) RID_EXTERN))
  6254.           current_extern_inline = 1;
  6255.       }
  6256.     if (was_overloaded)
  6257.       {
  6258.         DECL_OVERLOADED (decl) = 1;
  6259.         DECL_ORIGINAL_NAME (decl) = original_name;
  6260.       }
  6261.       }
  6262.     else
  6263.       {
  6264.     /* It's a variable.  */
  6265.  
  6266.     if (virtualp)
  6267.       error ("variable declared `virtual'");
  6268.     if (inlinep)
  6269.       warning ("variable declared `inline'");
  6270.     if (quals)
  6271.       error ("`const' and `volatile' function specifiers invalid in field declaration");
  6272.     if (friendp)
  6273.       error ("invalid friend declaration");
  6274.     if (raises)
  6275.       error ("invalid raises declaration");
  6276.  
  6277.     /* An uninitialized decl with `extern' is a reference.  */
  6278.     decl = grokvardecl (ctype, type, declarator, specbits, initialized);
  6279.       }
  6280.  
  6281.     /* Record `register' declaration for warnings on &
  6282.        and in case doing stupid register allocation.  */
  6283.  
  6284.     if (specbits & (1 << (int) RID_REGISTER))
  6285.       TREE_REGDECL (decl) = 1;
  6286.  
  6287.     /* Record constancy and volatility.  */
  6288.  
  6289.     if (constp)
  6290.       TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
  6291.     if (volatilep)
  6292.       {
  6293.     TREE_VOLATILE (decl) = 1;
  6294.     TREE_THIS_VOLATILE (decl) = 1;
  6295.       }
  6296.  
  6297.     if (TREE_CODE (decl) != FUNCTION_DECL
  6298.     && DECL_NAME (decl)
  6299.     && explicit_type == 0)
  6300.       warning ("type specifier for member `%s' omitted",
  6301.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  6302.  
  6303.     if (resume_temporary)
  6304.       resume_temporary_allocation ();
  6305.  
  6306.     return decl;
  6307.   }
  6308. }
  6309.  
  6310. /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
  6311.    An empty exprlist is a parmlist.  An exprlist which
  6312.    contains only identifiers at the global level
  6313.    is a parmlist.  Otherwise, it is an exprlist. */
  6314. static int
  6315. parmlist_is_exprlist (exprs)
  6316.      tree exprs;
  6317. {
  6318.   if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
  6319.     return 0;
  6320.  
  6321.   if (current_binding_level == global_binding_level)
  6322.     {
  6323.       /* At the global level, if these are all identifiers,
  6324.      then it is a parmlist.  */
  6325.       while (exprs)
  6326.     {
  6327.       if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
  6328.         return 1;
  6329.       exprs = TREE_CHAIN (exprs);
  6330.     }
  6331.       return 0;
  6332.     }
  6333.   return 1;
  6334. }
  6335.  
  6336. /* Make sure that the this list of PARMS has a chance of being
  6337.    grokked by `grokparms'.
  6338.  
  6339.    @@ This is really weak, but the grammar does not allow us
  6340.    @@ to easily reject things that this has to catch as syntax errors.  */
  6341. static int
  6342. parmlist_is_random (parms)
  6343.      tree parms;
  6344. {
  6345.   if (parms == NULL_TREE)
  6346.     return 0;
  6347.  
  6348.   if (TREE_CODE (parms) != TREE_LIST)
  6349.     return 1;
  6350.  
  6351.   while (parms)
  6352.     {
  6353.       if (parms == void_list_node)
  6354.     return 0;
  6355.  
  6356.       if (TREE_CODE (TREE_VALUE (parms)) != TREE_LIST)
  6357.     return 1;
  6358.       /* Don't get faked out by overloaded functions, which
  6359.      masquerade as TREE_LISTs!  */
  6360.       if (TREE_TYPE (TREE_VALUE (parms)) == unknown_type_node)
  6361.     return 1;
  6362.       parms = TREE_CHAIN (parms);
  6363.     }
  6364.   return 0;
  6365. }
  6366.  
  6367. /* Subroutine of `grokparms'.  In a fcn definition, arg types must
  6368.    be complete.
  6369.  
  6370.    C++: also subroutine of `start_function'.  */
  6371. static void
  6372. require_complete_types_for_parms (parms)
  6373.      tree parms;
  6374. {
  6375.   while (parms)
  6376.     {
  6377.       tree type = TREE_TYPE (parms);
  6378.       if (TYPE_SIZE (type) == 0)
  6379.     {
  6380.       if (DECL_NAME (parms))
  6381.         error ("parameter `%s' has incomplete type",
  6382.            IDENTIFIER_POINTER (DECL_NAME (parms)));
  6383.       else
  6384.         error ("parameter has incomplete type");
  6385.       TREE_TYPE (parms) = error_mark_node;
  6386.     }
  6387. #if 0
  6388.       /* If the arg types are incomplete in a declaration,
  6389.      they must include undefined tags.
  6390.      These tags can never be defined in the scope of the declaration,
  6391.      so the types can never be completed,
  6392.      and no call can be compiled successfully.  */
  6393.       /* This is not the right behavior for C++, but not having
  6394.      it is also probably wrong.  */
  6395.       else
  6396.     {
  6397.       /* Now warn if is a pointer to an incomplete type.  */
  6398.       while (TREE_CODE (type) == POINTER_TYPE
  6399.          || TREE_CODE (type) == REFERENCE_TYPE)
  6400.         type = TREE_TYPE (type);
  6401.       type = TYPE_MAIN_VARIANT (type);
  6402.       if (TYPE_SIZE (type) == 0)
  6403.         {
  6404.           if (DECL_NAME (parm) != 0)
  6405.         warning ("parameter `%s' points to incomplete type",
  6406.              IDENTIFIER_POINTER (DECL_NAME (parm)));
  6407.           else
  6408.         warning ("parameter points to incomplete type");
  6409.         }
  6410.     }
  6411. #endif
  6412.       parms = TREE_CHAIN (parms);
  6413.     }
  6414. }
  6415.  
  6416. /* Decode the list of parameter types for a function type.
  6417.    Given the list of things declared inside the parens,
  6418.    return a list of types.
  6419.  
  6420.    The list we receive can have three kinds of elements:
  6421.    an IDENTIFIER_NODE for names given without types,
  6422.    a TREE_LIST node for arguments given as typespecs or names with typespecs,
  6423.    or void_type_node, to mark the end of an argument list
  6424.    when additional arguments are not permitted (... was not used).
  6425.  
  6426.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  6427.    a mere declaration.  A nonempty identifier-list gets an error message
  6428.    when FUNCDEF_FLAG is zero.
  6429.    If FUNCDEF_FLAG is 1, then parameter types must be complete.
  6430.    If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
  6431.  
  6432.    If all elements of the input list contain types,
  6433.    we return a list of the types.
  6434.    If all elements contain no type (except perhaps a void_type_node
  6435.    at the end), we return a null list.
  6436.    If some have types and some do not, it is an error, and we
  6437.    return a null list.
  6438.  
  6439.    Also set last_function_parms to either
  6440.    a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
  6441.    A list of names is converted to a chain of PARM_DECLs
  6442.    by store_parm_decls so that ultimately it is always a chain of decls.
  6443.  
  6444.    Note that in C++, paramters can take default values.  These default
  6445.    values are in the TREE_PURPOSE field of the TREE_LIST.  It is
  6446.    an error to specify default values which are followed by parameters
  6447.    that have no defualt values, or an ELLIPSES.  For simplicities sake,
  6448.    only parameters which are specified with their types can take on
  6449.    default values.  */
  6450.  
  6451. static tree
  6452. grokparms (first_parm, funcdef_flag)
  6453.      tree first_parm;
  6454.      int funcdef_flag;
  6455. {
  6456.   tree result = NULL_TREE;
  6457.   tree decls = NULL_TREE;
  6458.  
  6459.   if (first_parm != 0
  6460.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  6461.     {
  6462.       if (! funcdef_flag)
  6463.     warning ("parameter names (without types) in function declaration");
  6464.       last_function_parms = first_parm;
  6465.       return 0;
  6466.     }
  6467.   else
  6468.     {
  6469.       /* Types were specified.  This is a list of declarators
  6470.      each represented as a TREE_LIST node.  */
  6471.       register tree parm, chain;
  6472.       int any_init = 0, any_error = 0, saw_void = 0;
  6473.  
  6474.       if (first_parm != NULL_TREE)
  6475.     {
  6476.       tree last_result = NULL_TREE;
  6477.       tree last_decl = NULL_TREE;
  6478.  
  6479.       for (parm = first_parm; parm != NULL_TREE; parm = chain)
  6480.         {
  6481.           tree type, list_node = parm;
  6482.           register tree decl = TREE_VALUE (parm);
  6483.           tree init = TREE_PURPOSE (parm);
  6484.  
  6485.           chain = TREE_CHAIN (parm);
  6486.           /* @@ weak defense against parse errors.  */
  6487.           if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
  6488.         {
  6489.           /* Give various messages as the need arises.  */
  6490.           if (TREE_CODE (decl) == STRING_CST)
  6491.             error ("invalid string constant `%s'",
  6492.                TREE_STRING_POINTER (decl));
  6493.           else if (TREE_CODE (decl) == INTEGER_CST)
  6494.             error ("invalid integer constant in parameter list, did you forget to give parameter name?");
  6495.           continue;
  6496.         }
  6497.  
  6498.           if (decl != void_type_node)
  6499.         {
  6500.           /* @@ May need to fetch out a `raises' here.  */
  6501.           decl = grokdeclarator (TREE_VALUE (decl),
  6502.                      TREE_PURPOSE (decl),
  6503.                      PARM, 0, NULL_TREE);
  6504.           if (! decl) continue;
  6505.           type = TREE_TYPE (decl);
  6506.           if (type == void_type_node)
  6507.             decl = void_type_node;
  6508.           else if (TREE_CODE (type) == METHOD_TYPE)
  6509.             {
  6510.               if (DECL_NAME (decl))
  6511.             /* Cannot use `error_with_decl' here because
  6512.                we don't have DECL_CONTEXT set up yet.  */
  6513.             error ("parameter `%s' invalidly declared method type",
  6514.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  6515.               else
  6516.             error ("parameter invalidly declared method type");
  6517.               type = build_pointer_type (type);
  6518.               TREE_TYPE (decl) = type;
  6519.             }
  6520.           else if (TREE_CODE (type) == OFFSET_TYPE)
  6521.             {
  6522.               if (DECL_NAME (decl))
  6523.             error ("parameter `%s' invalidly declared offset type",
  6524.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  6525.               else
  6526.             error ("parameter invalidly declared offset type");
  6527.               type = build_pointer_type (type);
  6528.               TREE_TYPE (decl) = type;
  6529.             }
  6530.         }
  6531.  
  6532.           if (decl == void_type_node)
  6533.         {
  6534.           if (result == NULL_TREE)
  6535.             {
  6536.               result = void_list_node;
  6537.               last_result = result;
  6538.             }
  6539.           else
  6540.             {
  6541.               TREE_CHAIN (last_result) = void_list_node;
  6542.               last_result = void_list_node;
  6543.             }
  6544.           saw_void = 1;
  6545.           if (chain
  6546.               && (chain != void_list_node || TREE_CHAIN (chain)))
  6547.             error ("`void' in parameter list must be entire list");
  6548.           break;
  6549.         }
  6550.  
  6551.           /* Since there is a prototype, args are passed in their own types.  */
  6552.           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
  6553. #ifdef PROMOTE_PROTOTYPES
  6554.           if (TREE_CODE (type) == INTEGER_TYPE
  6555.           && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  6556.         DECL_ARG_TYPE (decl) = integer_type_node;
  6557. #endif
  6558.           if (!any_error)
  6559.         {
  6560.           if (init)
  6561.             {
  6562.               any_init++;
  6563.               if (TREE_CODE (init) == SAVE_EXPR)
  6564.             PARM_DECL_EXPR (init) = 1;
  6565.               else
  6566.             init = require_instantiated_type (type, init, integer_zero_node);
  6567.             }
  6568.           else if (any_init)
  6569.             {
  6570.               error ("all trailing parameters must have default arguments");
  6571.               any_error = 1;
  6572.             }
  6573.         }
  6574.           else
  6575.         init = NULL_TREE;
  6576.  
  6577.           if (decls == NULL_TREE)
  6578.         {
  6579.           decls = decl;
  6580.           last_decl = decls;
  6581.         }
  6582.           else
  6583.         {
  6584.           TREE_CHAIN (last_decl) = decl;
  6585.           last_decl = decl;
  6586.         }
  6587.           if (TREE_PERMANENT (list_node))
  6588.         {
  6589.           TREE_PURPOSE (list_node) = init;
  6590.           TREE_VALUE (list_node) = type;
  6591.           TREE_CHAIN (list_node) = 0;
  6592.         }
  6593.           else
  6594.         list_node = saveable_tree_cons (init, type, NULL_TREE);
  6595.           if (result == NULL_TREE)
  6596.         {
  6597.           result = list_node;
  6598.           last_result = result;
  6599.         }
  6600.           else
  6601.         {
  6602.           TREE_CHAIN (last_result) = list_node;
  6603.           last_result = list_node;
  6604.         }
  6605.         }
  6606.       if (last_result)
  6607.         TREE_CHAIN (last_result) = NULL_TREE;
  6608.       /* If there are no parameters, and the function does not end
  6609.          with `...', then last_decl will be NULL_TREE.  */
  6610.       if (last_decl != NULL_TREE)
  6611.         TREE_CHAIN (last_decl) = NULL_TREE;
  6612.     }
  6613.     }
  6614.  
  6615.   last_function_parms = decls;
  6616.  
  6617.   /* In a fcn definition, arg types must be complete.  */
  6618.   if (funcdef_flag > 0)
  6619.     require_complete_types_for_parms (last_function_parms);
  6620.  
  6621.   return result;
  6622. }
  6623.  
  6624. /* These memoizing functions keep track of special properties which
  6625.    a class may have.  `grok_ctor_properties' notices whether a class
  6626.    has a constructor of the for X(X&), and also complains
  6627.    if the class has a constructor of the form X(X).
  6628.    `grok_op_properties' takes notice of the various forms of
  6629.    operator= which are defined, as well as what sorts of type conversion
  6630.    may apply.  Both functions take a FUNCTION_DECL as an argument.  */
  6631. static void
  6632. grok_ctor_properties (ctype, decl)
  6633.      tree ctype, decl;
  6634. {
  6635.   tree parmtypes = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)));
  6636.   tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  6637.  
  6638.   if (TREE_CODE (parmtype) == REFERENCE_TYPE
  6639.       && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
  6640.     {
  6641.       if (TREE_CHAIN (parmtypes) == NULL_TREE
  6642.       || TREE_CHAIN (parmtypes) == void_list_node
  6643.       || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
  6644.     {
  6645.       TYPE_HAS_INIT_REF (ctype) = 1;
  6646.       TYPE_GETS_INIT_REF (ctype) = 1;
  6647.       if (TREE_READONLY (TREE_TYPE (parmtype)))
  6648.         TYPE_GETS_CONST_INIT_REF (ctype) = 1;
  6649.     }
  6650.       else
  6651.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  6652.     }
  6653.   else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
  6654.     {
  6655.       if (TREE_CHAIN (parmtypes) != NULL_TREE
  6656.       && TREE_CHAIN (parmtypes) == void_list_node)
  6657.     error ("invalid constructor; you probably meant `%s (%s&)'",
  6658.            TYPE_NAME_STRING (ctype),
  6659.            TYPE_NAME_STRING (ctype));
  6660.       SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
  6661.       TYPE_GETS_INIT_AGGR (ctype) = 1;
  6662.     }
  6663.   else if (TREE_CODE (parmtype) == VOID_TYPE
  6664.        || TREE_PURPOSE (parmtypes) != NULL_TREE)
  6665.     TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
  6666. }
  6667.  
  6668. static void
  6669. grok_op_properties (decl)
  6670.      tree decl;
  6671. {
  6672.   char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
  6673.   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  6674.  
  6675.   if (DECL_STATIC_FUNCTION_P (decl))
  6676.     {
  6677.       if (! strncmp (name, OPERATOR_NEW_FORMAT, OPERATOR_NEW_LENGTH))
  6678.     {
  6679.       /* Take care of function decl if we had syntax errors.  */
  6680.       if (argtypes == NULL_TREE)
  6681.         TREE_TYPE (decl) = build_function_type (ptr_type_node,
  6682.                             hash_tree_chain (integer_type_node, void_list_node));
  6683.     }
  6684.       else if (! strncmp (name, OPERATOR_DELETE_FORMAT, OPERATOR_DELETE_LENGTH))
  6685.     {
  6686.       if (argtypes == NULL_TREE)
  6687.         TREE_TYPE (decl) = build_function_type (void_type_node,
  6688.                             hash_tree_chain (ptr_type_node, void_list_node));
  6689.     }
  6690.       else
  6691.     error_with_decl (decl, "`%s' cannot be a static member function");
  6692.     }
  6693.   else if (! strncmp (name, OPERATOR_MODIFY_FORMAT, OPERATOR_MODIFY_LENGTH))
  6694.     {
  6695.       tree parmtypes = TREE_CHAIN (argtypes);
  6696.       tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  6697.  
  6698.       if (TREE_CODE (parmtype) == REFERENCE_TYPE
  6699.       && TREE_TYPE (parmtype) == current_class_type)
  6700.     {
  6701.       TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
  6702.       TYPE_GETS_ASSIGN_REF (current_class_type) = 1;
  6703.       if (TREE_READONLY (TREE_TYPE (parmtype)))
  6704.         TYPE_GETS_CONST_INIT_REF (current_class_type) = 1;
  6705.     }
  6706.     }
  6707. }
  6708.  
  6709. /* Get the struct, enum or union (CODE says which) with tag NAME.
  6710.    Define the tag as a forward-reference if it is not defined.
  6711.  
  6712.    C++: If a class derivation is given, process it here, and report
  6713.    an error if multiple derivation declarations are not identical.
  6714.  
  6715.    If we are compiling for SOS, then
  6716.      if CODE_TYPE_NODE is a TREE_LIST, then we have a dynamic class
  6717.      declaration.  The name associated with the class is the tree
  6718.      purpose, and the real CODE is in the tree value slot.  */
  6719. tree
  6720. xref_tag (code_type_node, name, binfo)
  6721.      tree code_type_node;
  6722.      tree name, binfo;
  6723. {
  6724.   enum tag_types tag_code;
  6725.   enum tree_code code;
  6726.   int temp = 0;
  6727.   int i, len;
  6728.   register tree ref;
  6729.   struct binding_level *b
  6730.     = (class_binding_level ? class_binding_level : current_binding_level);
  6731. #ifdef SOS
  6732.   tree dynamic_name = error_mark_node;
  6733.   if (TREE_CODE (code_type_node) == TREE_LIST)
  6734.     {
  6735.       dynamic_name = TREE_PURPOSE (code_type_node);
  6736.       code_type_node = TREE_VALUE (code_type_node);
  6737.     }
  6738. #endif
  6739.  
  6740.   tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  6741.   switch (tag_code)
  6742.     {
  6743.     case record_type:
  6744.     case class_type:
  6745.     case exception_type:
  6746.       code = RECORD_TYPE;
  6747.       len = list_length (binfo) + 1;
  6748.       break;
  6749.     case union_type:
  6750.       code = UNION_TYPE;
  6751.       if (binfo)
  6752.     {
  6753.       error ("derived union `%s' invalid", IDENTIFIER_POINTER (name));
  6754.       binfo = NULL_TREE;
  6755.     }
  6756.       len = 1;
  6757.       break;
  6758.     case enum_type:
  6759.       code = ENUMERAL_TYPE;
  6760.       break;
  6761.     default:
  6762.       abort ();
  6763.     }
  6764.  
  6765.   /* If a cross reference is requested, look up the type
  6766.      already defined for this tag and return it.  */
  6767.   ref = lookup_tag (code, name, b, 0);
  6768.  
  6769.   if (! ref)
  6770.     {
  6771.       /* Try finding it as a type declaration.  If that wins, use it.  */
  6772.       ref = lookup_name (name);
  6773.       if (ref && TREE_CODE (ref) == TYPE_DECL
  6774.          && TREE_CODE (TREE_TYPE (ref)) == code)
  6775.     ref = TREE_TYPE (ref);
  6776.       else
  6777.     ref = NULL_TREE;
  6778.     }
  6779.  
  6780.   if (! ref)
  6781.     {
  6782.       /* If no such tag is yet defined, create a forward-reference node
  6783.      and record it as the "definition".
  6784.      When a real declaration of this type is found,
  6785.      the forward-reference will be altered into a real type.  */
  6786.  
  6787.       /* In C++, since these migrate into the global scope, we must
  6788.      build them on the permanent obstack.  */
  6789.       if (temp == 0)
  6790.     temp = allocation_temporary_p ();
  6791.       if (temp)
  6792.     end_temporary_allocation ();
  6793.  
  6794.       if (code == ENUMERAL_TYPE)
  6795.     {
  6796.       ref = make_node (ENUMERAL_TYPE);
  6797.  
  6798.       /* Give the type a default layout like unsigned int
  6799.          to avoid crashing if it does not get defined.  */
  6800.       TYPE_MODE (ref) = SImode;
  6801.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  6802.       TREE_UNSIGNED (ref) = 1;
  6803.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  6804.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  6805.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  6806.  
  6807.       /* Enable us to recognize when a type is created in class context.
  6808.          To do nested classes correctly, this should probably be cleared
  6809.          out when we leave this classes scope.  Currently this in only
  6810.          done in `start_enum'.  */
  6811.  
  6812.       pushtag (name, ref);
  6813.     }
  6814.       else if (tag_code == exception_type)
  6815.     {
  6816.       ref = make_lang_type (code);
  6817.       CLASSTYPE_OFFSET (ref) = integer_zero_node;
  6818.       /* Enable us to recognize when an exception type is created in
  6819.          class context.  To do nested classes correctly, this should
  6820.          probably be cleared out when we leave this class's scope.  */
  6821.       CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
  6822.       pushtag (name, ref);
  6823.     }
  6824.       else
  6825.     {
  6826.       extern tree pending_vtables;
  6827.       struct binding_level *old_b = class_binding_level;
  6828.       int needs_writing;
  6829.  
  6830.       ref = make_lang_type (code);
  6831.  
  6832.       CLASSTYPE_BASECLASSES (ref) = (tree *) malloc (len * sizeof (tree));
  6833.       CLASSTYPE_N_BASECLASSES (ref) = len - 1;
  6834.       CLASSTYPE_OFFSET (ref) = integer_zero_node;
  6835.       CLASSTYPE_VIAS (ref) = (unsigned char *) malloc (len);
  6836.  
  6837.       /* Record how to set the visibility of this class's
  6838.          virtual functions.  If write_virtuals == 2 or 3, then
  6839.          inline virtuals are ``extern inline''.  */
  6840.       switch (write_virtuals)
  6841.         {
  6842.         case 0:
  6843.         case 1:
  6844.           needs_writing = 1;
  6845.           break;
  6846.         case 2:
  6847.           needs_writing = !! value_member (name, pending_vtables);
  6848.           break;
  6849.         case 3:
  6850.           needs_writing
  6851.         = ! (CLASSTYPE_INTERFACE_ONLY (ref) || CLASSTYPE_INTERFACE_UNKNOWN (ref));
  6852.           break;
  6853.         default:
  6854.           needs_writing = 0;
  6855.         }
  6856.  
  6857.       CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
  6858.  
  6859.       /* Class types don't nest the way enums do.  */
  6860.       class_binding_level = 0;
  6861.       pushtag (name, ref);
  6862.       class_binding_level = old_b;
  6863.     }
  6864.     }
  6865.   else
  6866.     {
  6867.       if (IS_AGGR_TYPE_CODE (code))
  6868.     {
  6869. #if 0
  6870.       if (TREE_CODE (TYPE_NAME (ref)) == IDENTIFIER_NODE
  6871. #ifndef BREAK_C_TAGS
  6872.           && current_lang_name == lang_name_cplusplus
  6873. #endif
  6874.           && ! CLASSTYPE_DECLARED_EXCEPTION (ref))
  6875.         {
  6876.           /* Silently typedef a tag which came from C.  */
  6877.           register tree t = pushdecl (build_decl (TYPE_DECL, name, ref));
  6878.           TYPE_NAME (ref) = t;
  6879.           TREE_TYPE (name) = t;
  6880.         }
  6881. #endif
  6882.       if (IS_AGGR_TYPE (ref)
  6883.           && ((tag_code == exception_type)
  6884.           != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
  6885.         {
  6886.           error ("type `%s' is both exception and aggregate type",
  6887.              IDENTIFIER_POINTER (name));
  6888.           CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
  6889.         }
  6890.     }
  6891.       if (binfo)
  6892.     {
  6893.       tree tt1 = binfo;
  6894.       tree *tt2 = CLASSTYPE_BASECLASSES (ref);
  6895.  
  6896.       if (CLASSTYPE_N_BASECLASSES (ref))
  6897.         for (i = 1; tt1; i++, tt1 = TREE_CHAIN (tt1))
  6898.           if (TREE_VALUE (tt1) != DECL_NAME (TYPE_NAME (tt2[i])))
  6899.         {
  6900.           error ("redeclaration of derivation chain of type `%s'",
  6901.              IDENTIFIER_POINTER (name));
  6902.           break;
  6903.         }
  6904.  
  6905.       if (tt1 != NULL_TREE)
  6906.         {
  6907.           if (CLASSTYPE_BASECLASSES (ref))
  6908.         free (CLASSTYPE_BASECLASSES (ref));
  6909.           if (CLASSTYPE_VIAS (ref))
  6910.         free (CLASSTYPE_VIAS (ref));
  6911.           CLASSTYPE_BASECLASSES (ref) = (tree *) malloc (len * sizeof (tree));
  6912.           CLASSTYPE_N_BASECLASSES (ref) = len - 1;
  6913.           CLASSTYPE_OFFSET (ref) = integer_zero_node;
  6914.           CLASSTYPE_ASSOC (ref) = NULL_TREE;
  6915.           CLASSTYPE_VIAS (ref) = (unsigned char *) malloc (len);
  6916.         }
  6917.       else
  6918.         {
  6919.           /* The user told us something we already knew.  */
  6920.           goto just_return;
  6921.         }
  6922.     }
  6923. #ifdef SOS
  6924.       else if (TREE_CODE (ref) != ENUMERAL_TYPE
  6925.            && (dynamic_name != error_mark_node) != TYPE_DYNAMIC (ref))
  6926.     error ("type `%s' declared both dynamic and non-dynamic",
  6927.            IDENTIFIER_POINTER (name));
  6928. #endif
  6929.     }
  6930.  
  6931.   if (binfo)
  6932.     {
  6933.       CLASSTYPE_MARKED (ref) = 1;
  6934.       for (i = 1; binfo; binfo = TREE_CHAIN (binfo))
  6935.     {
  6936.       /* The base of a derived struct is public.  */
  6937.       int via_public = (tag_code != class_type
  6938.                 || TREE_PURPOSE (binfo) == (tree)visibility_public
  6939.                 || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual);
  6940.       int via_virtual = (TREE_PURPOSE (binfo) == (tree)visibility_private_virtual
  6941.                  || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual
  6942.                  || TREE_PURPOSE (binfo) == (tree)visibility_default_virtual);
  6943.       tree basetype = TREE_TYPE (TREE_VALUE (binfo));
  6944.  
  6945. #ifdef FIELD_XREF
  6946.       FIELD_xref_hier(IDENTIFIER_POINTER(name),
  6947.               IDENTIFIER_POINTER(TREE_VALUE(binfo)),
  6948.               via_public,via_virtual,0);
  6949. #endif
  6950.  
  6951.       if (basetype && TREE_CODE (basetype) == TYPE_DECL)
  6952.         basetype = TREE_TYPE (basetype);
  6953.       if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
  6954.         {
  6955.           error ("base type `%s' fails to be a struct or class type",
  6956.              IDENTIFIER_POINTER (TREE_VALUE (binfo)));
  6957.           continue;
  6958.         }
  6959. #if 0
  6960.       else if (TYPE_SIZE (basetype) == 0)
  6961.         {
  6962.           error_with_aggr_type (basetype, "base class `%s' has incomplete type");
  6963.           continue;
  6964.         }
  6965. #endif
  6966.       else
  6967.         {
  6968. #ifdef SOS
  6969.           if (dynamic_name == error_mark_node && TYPE_DYNAMIC (basetype))
  6970.         error_with_aggr_type (ref, "non-dynamic type `%s' cannot derive from dynamic type `%s'", TYPE_NAME_STRING (basetype));
  6971. #endif
  6972.           if (CLASSTYPE_MARKED (basetype))
  6973.         {
  6974.           if (basetype == ref)
  6975.             error_with_aggr_type (basetype, "recursive type `%s' undefined");
  6976.           else
  6977.             error_with_aggr_type (basetype, "duplicate base type `%s' invalid");
  6978.           continue;
  6979.         }
  6980.           CLASSTYPE_BASECLASS (ref, i) = basetype;
  6981.           CLASSTYPE_MARKED (basetype) = 1;
  6982. #if 0
  6983. /* XYZZY TEST VIRTUAL BASECLASSES */
  6984. if (CLASSTYPE_N_BASECLASSES (basetype) == 0
  6985.     && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
  6986.     && via_virtual == 0)
  6987.   {
  6988.     warning ("making type `%s' a virtual baseclass",
  6989.          TYPE_NAME_STRING (basetype));
  6990.     via_virtual = 1;
  6991.   }
  6992. #endif
  6993.           SET_CLASSTYPE_VIAS (ref, i, via_public, via_virtual);
  6994.           if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
  6995.         TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
  6996.  
  6997.           TYPE_GETS_ASSIGNMENT (ref) |= TYPE_GETS_ASSIGNMENT (basetype);
  6998.           TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
  6999.           TYPE_HAS_WRAPPER_PRED (ref) |= TYPE_HAS_WRAPPER_PRED (basetype);
  7000.           TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype);
  7001.           TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype);
  7002.           CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
  7003.           i += 1;
  7004.         }
  7005.     }
  7006.       /* Set the true number of baseclasses this type really has.  */
  7007.       CLASSTYPE_N_BASECLASSES (ref) = --i;
  7008.  
  7009.       if (i > 1)
  7010.     TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
  7011.       else if (i == 1)
  7012.     TYPE_USES_MULTIPLE_INHERITANCE (ref)
  7013.       = TYPE_USES_MULTIPLE_INHERITANCE (CLASSTYPE_BASECLASS (ref, 1));
  7014.  
  7015.       while (i > 0)
  7016.     {
  7017.       CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (ref, i)) = 0;
  7018.       i -= 1;
  7019.     }
  7020.       CLASSTYPE_MARKED (ref) = 0;
  7021.     }
  7022.  
  7023.  just_return:
  7024.  
  7025. #ifdef SOS
  7026.   if (dynamic_name != error_mark_node)
  7027.     {
  7028.       if (temp == 0)
  7029.     temp = allocation_temporary_p ();
  7030.       if (temp)
  7031.     end_temporary_allocation ();
  7032.  
  7033.       if (dynamic_name)
  7034.     CLASSTYPE_DYNAMIC_FILENAME (ref) = combine_strings (dynamic_name);
  7035.       else
  7036.     CLASSTYPE_DYNAMIC_FILENAME (ref) = NULL_TREE;
  7037.       TYPE_DYNAMIC (ref) = 1;
  7038.       CLASSTYPE_TYPENAME_AS_STRING (ref) = combine_strings (build_string (IDENTIFIER_LENGTH (name), IDENTIFIER_POINTER (name)));
  7039.  
  7040.     }
  7041. #endif
  7042.  
  7043.   /* Until the type is defined, tentatively accept whatever
  7044.      structure tag the user hands us.  */
  7045.   if (TYPE_SIZE (ref) == NULL_TREE
  7046.       && ref != current_class_type
  7047.       && IS_AGGR_TYPE (ref))
  7048.     {
  7049.       if (tag_code == class_type)
  7050.     CLASSTYPE_DECLARED_CLASS (ref) = 1;
  7051.       else if (tag_code == record_type)
  7052.     CLASSTYPE_DECLARED_CLASS (ref) = 0;
  7053.     }
  7054.  
  7055.   if (temp)
  7056.     resume_temporary_allocation ();
  7057.  
  7058.   return ref;
  7059. }
  7060.  
  7061. /* Begin compiling the definition of an enumeration type.
  7062.    NAME is its name (or null if anonymous).
  7063.    Returns the type object, as yet incomplete.
  7064.    Also records info about it so that build_enumerator
  7065.    may be used to declare the individual values as they are read.  */
  7066.  
  7067. tree
  7068. start_enum (name)
  7069.      tree name;
  7070. {
  7071.   register tree enumtype = 0;
  7072.   struct binding_level *b
  7073.     = (class_binding_level ? class_binding_level : current_binding_level);
  7074.  
  7075.   /* If this is the real definition for a previous forward reference,
  7076.      fill in the contents in the same object that used to be the
  7077.      forward reference.  */
  7078.  
  7079.   if (name != 0)
  7080.     enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
  7081.  
  7082.   if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
  7083.     {
  7084.       enumtype = make_node (ENUMERAL_TYPE);
  7085.       pushtag (name, enumtype);
  7086.     }
  7087.  
  7088.   if (TYPE_VALUES (enumtype) != 0)
  7089.     {
  7090.       /* This enum is a named one that has been declared already.  */
  7091.       error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
  7092.  
  7093.       /* Completely replace its old definition.
  7094.      The old enumerators remain defined, however.  */
  7095.       TYPE_VALUES (enumtype) = 0;
  7096.     }
  7097.  
  7098.   /* Initially, set up this enum as like `int'
  7099.      so that we can create the enumerators' declarations and values.
  7100.      Later on, the precision of the type may be changed and
  7101.      it may be laid out again.  */
  7102.  
  7103.   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  7104.   TYPE_SIZE (enumtype) = 0;
  7105.   fixup_unsigned_type (enumtype);
  7106.  
  7107.   /* We copy this value because enumerated type constants
  7108.      are really of the type of the enumerator, not integer_type_node.  */
  7109.   enum_next_value = copy_node (integer_zero_node);
  7110.  
  7111. #ifdef FIELD_XREF
  7112.   FIELD_xref_decl(current_function_decl,enumtype);
  7113. #endif
  7114.  
  7115.   return enumtype;
  7116. }
  7117.  
  7118. /* After processing and defining all the values of an enumeration type,
  7119.    install their decls in the enumeration type and finish it off.
  7120.    ENUMTYPE is the type object and VALUES a list of name-value pairs.
  7121.    Returns ENUMTYPE.  */
  7122.  
  7123. tree
  7124. finish_enum (enumtype, values)
  7125.      register tree enumtype, values;
  7126. {
  7127.   register tree pair;
  7128.   register long maxvalue = 0;
  7129.   register long minvalue = 0;
  7130.   register int i;
  7131.  
  7132.   TYPE_VALUES (enumtype) = values;
  7133.  
  7134.   /* Calculate the maximum value of any enumerator in this type.  */
  7135.  
  7136.   if (values)
  7137.     {
  7138.       /* Speed up the main loop by performing some precalculations */
  7139.  
  7140.       int value = TREE_INT_CST_LOW (TREE_VALUE (values));
  7141.       TREE_TYPE (TREE_VALUE (values)) = enumtype;
  7142.       minvalue = maxvalue = value;
  7143.       
  7144.       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
  7145.     {
  7146.       value = TREE_INT_CST_LOW (TREE_VALUE (pair));
  7147.       if (value > maxvalue)
  7148.         maxvalue = value;
  7149.       else if (value < minvalue)
  7150.         minvalue = value;
  7151.       TREE_TYPE (TREE_VALUE (pair)) = enumtype;
  7152.     }
  7153.     }
  7154.  
  7155.   if (flag_short_enums)
  7156.     {
  7157.       /* Determine the precision this type needs, lay it out, and define it.  */
  7158.  
  7159.       for (i = maxvalue; i; i >>= 1)
  7160.     TYPE_PRECISION (enumtype)++;
  7161.  
  7162.       if (!TYPE_PRECISION (enumtype))
  7163.     TYPE_PRECISION (enumtype) = 1;
  7164.  
  7165.       /* Cancel the laying out previously done for the enum type,
  7166.      so that fixup_unsigned_type will do it over.  */
  7167.       TYPE_SIZE (enumtype) = 0;
  7168.  
  7169.       fixup_unsigned_type (enumtype);
  7170.     }
  7171.  
  7172.   TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
  7173.  
  7174.   /* An enum can have some negative values; then it is signed.  */
  7175.   if (minvalue < 0)
  7176.     {
  7177.       TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
  7178.       TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
  7179.       TREE_UNSIGNED (enumtype) = 0;
  7180.     }
  7181.   return enumtype;
  7182. }
  7183.  
  7184. /* Build and install a CONST_DECL for one value of the
  7185.    current enumeration type (one that was begun with start_enum).
  7186.    Return a tree-list containing the name and its value.
  7187.    Assignment of sequential values by default is handled here.  */
  7188.  
  7189. tree
  7190. build_enumerator (name, value)
  7191.      tree name, value;
  7192. {
  7193.   tree decl, result;
  7194.  
  7195.   /* Validate and default VALUE.  */
  7196.   if (value != 0)
  7197.     {
  7198.       if (TREE_READONLY_DECL_P (value))
  7199.     value = decl_constant_value (value);
  7200.  
  7201.       if (TREE_CODE (value) != INTEGER_CST)
  7202.     {
  7203.       error ("enumerator value for `%s' not integer constant",
  7204.          IDENTIFIER_POINTER (name));
  7205.       value = 0;
  7206.     }
  7207.     }
  7208.   /* The order of things is reversed here so that we
  7209.      can check for possible sharing of enum values,
  7210.      to keep that from happening.  */
  7211.   /* Default based on previous value.  */
  7212.   if (value == 0)
  7213.     value = enum_next_value;
  7214.  
  7215.   /* Remove no-op casts from the value.  */
  7216.   while (value != 0 && TREE_CODE (value) == NOP_EXPR)
  7217.     value = TREE_OPERAND (value, 0);
  7218.  
  7219.   /* Make up for hacks in cplus-lex.c.  */
  7220.   if (value == integer_zero_node)
  7221.     value = build_int_2 (0, 0);
  7222.   else if (value == integer_one_node)
  7223.     value = build_int_2 (1, 0);
  7224.   else if (TREE_CODE (value) == INTEGER_CST
  7225.        && TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)
  7226.     {
  7227.       value = copy_node (value);
  7228.       TREE_TYPE (value) = integer_type_node;
  7229.     }
  7230.  
  7231.   result = saveable_tree_cons (name, value, NULL_TREE);
  7232.  
  7233.   /* C++ associates enums with global, function, or class declarations.  */
  7234.   if (current_class_type == NULL_TREE || current_function_decl != NULL_TREE)
  7235.     {
  7236.       /* Create a declaration for the enum value name.  */
  7237.  
  7238.       decl = build_decl (CONST_DECL, name, integer_type_node);
  7239.       DECL_INITIAL (decl) = value;
  7240.  
  7241.       pushdecl (decl);
  7242.     }
  7243.  
  7244.   /* Set basis for default for next value.  */
  7245.   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  7246.                            integer_one_node, PLUS_EXPR);
  7247.   if (TREE_UID (enum_next_value) < TREE_UID (result))
  7248.     enum_next_value = copy_node (enum_next_value);
  7249.  
  7250.   return result;
  7251. }
  7252.  
  7253. tree
  7254. grok_enum_decls (type, decl)
  7255.      tree type, decl;
  7256. {
  7257.   struct binding_level *b = class_binding_level;
  7258.   tree tag = NULL_TREE;
  7259.   tree values;
  7260.  
  7261.   while (b)
  7262.     {
  7263.       tag = value_member (type, b->tags);
  7264.       if (tag)
  7265.     break;
  7266.       b = b->level_chain;
  7267.     }
  7268.  
  7269.   if (b == 0)
  7270.     {
  7271.       tree name = TYPE_NAME (type);
  7272.       if (TREE_CODE (name) == TYPE_DECL)
  7273.     name = DECL_NAME (name);
  7274.       error ("class-local enum declaration `%s' is not in scope here",
  7275.          IDENTIFIER_POINTER (name));
  7276.     }
  7277.   else if (b != class_binding_level)
  7278.     {
  7279.       warning ("class-local declaration for enumeral type `%s' found",
  7280.            IDENTIFIER_POINTER (TREE_PURPOSE (tag)));
  7281.       warning ("(probably missing '}' before that enum declaration)");
  7282.       return decl;
  7283.     }
  7284.   else if (TREE_ADDRESSABLE (tag))
  7285.     return decl;
  7286.   else
  7287.     TREE_ADDRESSABLE (tag) = 1;
  7288.  
  7289.   values = TYPE_VALUES (type);
  7290.   while (values)
  7291.     {
  7292.       /* Create a declaration for the enum value name.  */
  7293.       tree next = build_lang_field_decl (CONST_DECL, TREE_PURPOSE (values), type);
  7294.       DECL_INITIAL (next) = TREE_VALUE (values);
  7295.       TREE_CHAIN (next) = decl;
  7296.       decl = next;
  7297.       pushdecl_class_level (decl);
  7298.       values = TREE_CHAIN (values);
  7299.     }
  7300.   return decl;
  7301. }
  7302.  
  7303. /* Create the FUNCTION_DECL for a function definition.
  7304.    DECLSPECS and DECLARATOR are the parts of the declaration;
  7305.    they describe the function's name and the type it returns,
  7306.    but twisted together in a fashion that parallels the syntax of C.
  7307.  
  7308.    This function creates a binding context for the function body
  7309.    as well as setting up the FUNCTION_DECL in current_function_decl.
  7310.  
  7311.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  7312.    (it defines a datum instead), we return 0, which tells
  7313.    yyparse to report a parse error.
  7314.  
  7315.    For C++, we must first check whether that datum makes any sense.
  7316.    For example, "class A local_a(1,2);" means that variable local
  7317.    a is an aggregate of type A, which should have a constructor
  7318.    applied to it with the argument list [1, 2].
  7319.  
  7320.    @@ There is currently no way to retrieve the storage
  7321.    @@ allocated to FUNCTION (or all of its parms) if we return
  7322.    @@ something we had previously.  */
  7323.  
  7324. int
  7325. start_function (declspecs, declarator, raises, pre_parsed_p)
  7326.      tree declarator, declspecs, raises;
  7327.      int pre_parsed_p;
  7328. {
  7329.   extern tree EHS_decl;
  7330.   tree decl1, olddecl;
  7331.   tree ctype = NULL_TREE;
  7332.   tree fntype;
  7333.   tree restype;
  7334.  
  7335.   if (flag_handle_exceptions && EHS_decl == NULL_TREE)
  7336.     init_exception_processing_1 ();
  7337.  
  7338.   /* Sanity check.  */
  7339.   assert (TREE_VALUE (void_list_node) == void_type_node);
  7340.   assert (TREE_CHAIN (void_list_node) == NULL_TREE);
  7341.  
  7342.   /* Assume, until we see it does. */
  7343.   current_function_returns_value = 0;
  7344.   current_function_returns_null = 0;
  7345.   warn_about_return_type = 0;
  7346.   current_extern_inline = 0;
  7347.   current_function_assigns_this = 0;
  7348.   current_function_just_assigned_this = 0;
  7349.   current_function_parms_stored = 0;
  7350.   original_result_rtx = 0;
  7351.  
  7352.   clear_temp_name ();
  7353.  
  7354.   if (pre_parsed_p)
  7355.     {
  7356.       decl1 = declarator;
  7357.       last_function_parms = DECL_ARGUMENTS (decl1);
  7358.       last_function_parm_tags = 0;
  7359.       fntype = TREE_TYPE (decl1);
  7360.       if (TREE_CODE (fntype) == METHOD_TYPE)
  7361.     ctype = TYPE_METHOD_BASETYPE (fntype);
  7362.  
  7363.       if ( !(DECL_VIRTUAL_P (decl1)
  7364.          && write_virtuals >= 2
  7365.          && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
  7366.     current_extern_inline = TREE_PUBLIC (decl1);
  7367.  
  7368.       raises = TYPE_RAISES_EXCEPTIONS (fntype);
  7369.  
  7370.       /* In a fcn definition, arg types must be complete.  */
  7371.       require_complete_types_for_parms (last_function_parms);
  7372.     }
  7373.   else
  7374.     {
  7375.       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
  7376.       /* If the declarator is not suitable for a function definition,
  7377.      cause a syntax error.  */
  7378.       if (decl1 == 0 || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
  7379.  
  7380.       fntype = TREE_TYPE (decl1);
  7381.  
  7382.       restype = TREE_TYPE (fntype);
  7383.       if (IS_AGGR_TYPE (restype)
  7384.       && ! CLASSTYPE_GOT_SEMICOLON (restype))
  7385.     {
  7386.       error_with_aggr_type (restype, "semicolon missing after declaration of `%s'");
  7387.       shadow_tag (build_tree_list (NULL_TREE, restype));
  7388.       CLASSTYPE_GOT_SEMICOLON (restype) = 1;
  7389.       if (TREE_CODE (fntype) == FUNCTION_TYPE)
  7390.         fntype = build_function_type (integer_type_node,
  7391.                       TYPE_ARG_TYPES (fntype));
  7392.       else
  7393.         fntype = build_cplus_method_type (TYPE_METHOD_BASETYPE (fntype),
  7394.                           integer_type_node,
  7395.                           TYPE_ARG_TYPES (fntype));
  7396.       TREE_TYPE (decl1) = fntype;
  7397.     }
  7398.  
  7399.       if (TREE_CODE (fntype) == METHOD_TYPE)
  7400.     ctype = TYPE_METHOD_BASETYPE (fntype);
  7401.       else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
  7402.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main"))
  7403.     {
  7404.       /* If this doesn't return an integer type, complain.  */
  7405.       if (TREE_CODE (TREE_TYPE (fntype)) != INTEGER_TYPE)
  7406.         {
  7407. #if 0
  7408.           error ("return type for `main' must be integer type");
  7409. #else
  7410.           warning ("return type for `main' changed to integer type");
  7411. #endif
  7412.           TREE_TYPE (decl1) = fntype = default_function_type;
  7413.         }
  7414.       warn_about_return_type = 0;
  7415.     }
  7416.     }
  7417.  
  7418.   /* Warn if function was previously implicitly declared
  7419.      (but not if we warned then).  */
  7420.   if (! warn_implicit && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != 0)
  7421.     warning_with_decl (IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)),
  7422.                "`%s' implicitly declared before its definition");
  7423.  
  7424.   current_function_decl = decl1;
  7425.  
  7426.   announce_function (decl1);
  7427.  
  7428.   if (TYPE_SIZE (TREE_TYPE (fntype)) == 0)
  7429.     {
  7430.       if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
  7431.     error_with_aggr_type (TREE_TYPE (fntype),
  7432.                   "return-type `%s' is an incomplete type");
  7433.       else
  7434.     error ("return-type is an incomplete type");
  7435.  
  7436.       /* Make it return void instead.  */
  7437.       if (ctype)
  7438.     TREE_TYPE (decl1)
  7439.       = build_cplus_method_type (ctype,
  7440.                      void_type_node,
  7441.                      TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl1))));
  7442.       else
  7443.     TREE_TYPE (decl1)
  7444.       = build_function_type (void_type_node,
  7445.                  TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  7446.     }
  7447.  
  7448.   if (warn_about_return_type)
  7449.     warning ("return-type defaults to `int'");
  7450.  
  7451.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  7452.      error_mark_node is replaced below (in poplevel) with the LET_STMT.  */
  7453.   DECL_INITIAL (decl1) = error_mark_node;
  7454.  
  7455.   /* Didn't get anything from C.  */
  7456.   olddecl = 0;
  7457.  
  7458.   /* This is a definition, not a reference.
  7459.      So normally clear TREE_EXTERNAL.
  7460.      However, `extern inline' acts like a declaration
  7461.      except for defining how to inline.  So set TREE_EXTERNAL in that case.  */
  7462.   TREE_EXTERNAL (decl1) = current_extern_inline;
  7463.  
  7464.   /* This function exists in static storage.
  7465.      (This does not mean `static' in the C sense!)  */
  7466.   TREE_STATIC (decl1) = 1;
  7467.  
  7468.   /* If this function belongs to the implementation, make it public.
  7469.      It doesn't matter whether it's inline or not.   */
  7470.   if (!TREE_PRIVATE (decl1) && interface_unknown == 0)
  7471.     {
  7472.       TREE_PUBLIC (decl1) = ! interface_only;
  7473.       TREE_EXTERNAL (decl1) = interface_only;
  7474.     }
  7475.  
  7476.   /* Now see if this is the implementation of a function
  7477.      declared with "C" linkage.  */
  7478.   if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus)
  7479.     {
  7480.       olddecl = lookup_name_current_level (DECL_ORIGINAL_NAME (decl1));
  7481.       if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL)
  7482.     olddecl = NULL_TREE;
  7483.       if (olddecl
  7484.       && DECL_ORIGINAL_NAME (decl1) != DECL_ORIGINAL_NAME (olddecl))
  7485.     {
  7486.       /* Collision between user and internal naming scheme.  */
  7487.       olddecl = lookup_name_current_level (DECL_NAME (decl1));
  7488.       if (olddecl == NULL_TREE)
  7489.         olddecl = decl1;
  7490.     }
  7491.       if (olddecl && olddecl != decl1
  7492.       && DECL_ORIGINAL_NAME (decl1) == DECL_ORIGINAL_NAME (olddecl))
  7493.     {
  7494.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  7495.           && (decls_match (decl1, olddecl)
  7496.           || comp_target_parms (TYPE_ARG_TYPES (TREE_TYPE (decl1)),
  7497.                     TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 1)))
  7498.         {
  7499.           olddecl = DECL_MAIN_VARIANT (olddecl);
  7500.           DECL_NAME (decl1) = DECL_NAME (olddecl);
  7501.           DECL_PRINT_NAME (decl1) = DECL_PRINT_NAME (olddecl);
  7502.           DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl);
  7503.           if (DECL_INITIAL (olddecl))
  7504.         redeclaration_error_message (decl1, olddecl);
  7505.           if (! duplicate_decls (decl1, olddecl))
  7506.         abort ();
  7507.           decl1 = olddecl;
  7508.         }
  7509.       else
  7510.         olddecl = NULL_TREE;
  7511.     }
  7512.     }
  7513.  
  7514.   /* Record the decl so that the function name is defined.
  7515.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  7516.      use the old decl.  */
  7517.  
  7518.   if (olddecl)
  7519.     current_function_decl = olddecl;
  7520.   else if (pre_parsed_p == 0)
  7521.     {
  7522.       current_function_decl = pushdecl (decl1);
  7523.       if (TREE_CODE (current_function_decl) == TREE_LIST)
  7524.     {
  7525.       /* @@ revert to modified original declaration.  */
  7526.       decl1 = DECL_MAIN_VARIANT (decl1);
  7527.       current_function_decl = decl1;
  7528.     }
  7529.       else
  7530.     {
  7531.       decl1 = current_function_decl;
  7532.       DECL_MAIN_VARIANT (decl1) = decl1;
  7533.     }
  7534.       fntype = TREE_TYPE (decl1);
  7535.     }
  7536.   else
  7537.     current_function_decl = decl1;
  7538.  
  7539.   if (DECL_OVERLOADED (decl1))
  7540.     push_overloaded_decl (decl1);
  7541.  
  7542.   if (ctype != 0 && DECL_STATIC_FUNCTION_P (decl1))
  7543.     {
  7544.       if (TREE_CODE (fntype) == METHOD_TYPE)
  7545.     TREE_TYPE (decl1) = fntype
  7546.       = build_function_type (TREE_TYPE (fntype),
  7547.                  TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
  7548.       last_function_parms = TREE_CHAIN (last_function_parms);
  7549.       DECL_ARGUMENTS (decl1) = last_function_parms;
  7550.       ctype = 0;
  7551.     }
  7552.   restype = TREE_TYPE (fntype);
  7553.  
  7554.   pushlevel (0);
  7555.   current_binding_level->parm_flag = 1;
  7556.  
  7557.   /* Save the parm names or decls from this function's declarator
  7558.      where store_parm_decls will find them.  */
  7559.   current_function_parms = last_function_parms;
  7560.   current_function_parm_tags = last_function_parm_tags;
  7561.  
  7562. #ifdef FIELD_XREF
  7563.   FIELD_xref_function(decl1,current_function_parms);
  7564. #endif
  7565.  
  7566.   make_function_rtl (decl1);
  7567.  
  7568.   if (ctype)
  7569.     {
  7570.       pushclass (ctype, 1);
  7571.       /* We know that this was set up by `grokclassfn'.
  7572.      We do not wait until `store_parm_decls', since evil
  7573.      parse errors may never get us to that point.  Here
  7574.      we keep the consistency between `current_class_type'
  7575.      and `current_class_decl'.  */
  7576.       current_class_decl = last_function_parms;
  7577.       assert (TREE_CODE (current_class_decl) == PARM_DECL);
  7578.       if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
  7579.     {
  7580.       tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
  7581.       if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
  7582.         {
  7583.           /* Can't call build_indirect_ref here, because it has special
  7584.          logic to return C_C_D given this argument.  */
  7585.           C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
  7586.           CLASSTYPE_INST_VAR (ctype) = C_C_D;
  7587.         }
  7588.       else
  7589.         {
  7590.           C_C_D = CLASSTYPE_INST_VAR (ctype);
  7591.           /* `current_class_decl' is different for every
  7592.          function we compile.  */
  7593.           TREE_OPERAND (C_C_D, 0) = current_class_decl;
  7594.         }
  7595.       TREE_READONLY (C_C_D) = TREE_READONLY (variant);
  7596.       TREE_VOLATILE (C_C_D) = TREE_VOLATILE (variant);
  7597.     }
  7598.       else
  7599.     C_C_D = current_class_decl;
  7600.     }
  7601.   else
  7602.     {
  7603.       if (DECL_STATIC_FUNCTION_P (decl1))
  7604.     pushclass (DECL_STATIC_CONTEXT (decl1), 2);
  7605.       else
  7606.     push_memoized_context (0, 1);
  7607.     }
  7608.  
  7609.   /* Allocate further tree nodes temporarily during compilation
  7610.      of this function only.  */
  7611.   temporary_allocation ();
  7612.  
  7613.   /* Promote the value to int before returning it.  */
  7614.   if (TREE_CODE (restype) == INTEGER_TYPE
  7615.       && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
  7616.     restype = integer_type_node;
  7617.   DECL_RESULT (decl1) = build_decl (RESULT_DECL, value_identifier, restype);
  7618.  
  7619.   if (DESTRUCTOR_NAME_P (DECL_NAME (decl1)))
  7620.     {
  7621.       dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  7622.       ctor_label = NULL_TREE;
  7623.     }
  7624.   else
  7625.     {
  7626.       dtor_label = NULL_TREE;
  7627.       if (DECL_CONSTRUCTOR_P (decl1))
  7628.     ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  7629.     }
  7630.  
  7631.   /* If this fcn was already referenced via a block-scope `extern' decl
  7632.      (or an implicit decl), propagate certain information about the usage.  */
  7633.   if (TREE_ADDRESSABLE (DECL_NAME (decl1)))
  7634.     TREE_ADDRESSABLE (decl1) = 1;
  7635.  
  7636.   return 1;
  7637. }
  7638.  
  7639. /* Store the parameter declarations into the current function declaration.
  7640.    This is called after parsing the parameter declarations, before
  7641.    digesting the body of the function.
  7642.  
  7643.    Also install to binding contour return value identifier, if any.  */
  7644.  
  7645. void
  7646. store_parm_decls ()
  7647. {
  7648.   register tree fndecl = current_function_decl;
  7649.   register tree parm;
  7650.   int parms_have_cleanups = 0;
  7651.   tree eh_decl;
  7652.  
  7653.   /* This is either a chain of PARM_DECLs (when a prototype is used).  */
  7654.   tree specparms = current_function_parms;
  7655.  
  7656.   /* This is a list of types declared among parms in a prototype.  */
  7657.   tree parmtags = current_function_parm_tags;
  7658.  
  7659.   /* This is a chain of any other decls that came in among the parm
  7660.      declarations.  If a parm is declared with  enum {foo, bar} x;
  7661.      then CONST_DECLs for foo and bar are put here.  */
  7662.   tree nonparms = 0;
  7663.  
  7664.   if (current_binding_level == global_binding_level)
  7665.     fatal ("parse errors have confused me too much");
  7666.  
  7667.   /* Initialize RTL machinery.  */
  7668.   init_function_start (fndecl);
  7669.  
  7670.   /* Create a binding level for the parms.  */
  7671.   expand_start_bindings (0);
  7672.  
  7673.   /* Prepare to catch raises, if appropriate.  */
  7674.   if (flag_handle_exceptions)
  7675.     {
  7676.       /* Get this cleanup to be run last, since it
  7677.      is a call to `longjmp'.  */
  7678.       setup_exception_throw_decl ();
  7679.       eh_decl = current_binding_level->names;
  7680.       current_binding_level->names = TREE_CHAIN (current_binding_level->names);
  7681.     }
  7682.   if (flag_handle_exceptions)
  7683.     expand_start_try (integer_one_node, 0, 1);
  7684.  
  7685.   if (specparms != 0)
  7686.     {
  7687.       /* This case is when the function was defined with an ANSI prototype.
  7688.      The parms already have decls, so we need not do anything here
  7689.      except record them as in effect
  7690.      and complain if any redundant old-style parm decls were written.  */
  7691.  
  7692.       register tree next;
  7693.  
  7694.       for (parm = nreverse (specparms); parm; parm = next)
  7695.     {
  7696.       tree cleanup = maybe_build_cleanup (parm);
  7697.       next = TREE_CHAIN (parm);
  7698.       if (DECL_NAME (parm) == 0)
  7699.         {
  7700. #if 0
  7701.           error_with_decl (parm, "parameter name omitted");
  7702. #else
  7703.           /* for C++, this is not an error.  */
  7704.           pushdecl (parm);
  7705. #endif
  7706.         }
  7707.       else if (TREE_TYPE (parm) == void_type_node)
  7708.         error_with_decl (parm, "parameter `%s' declared void");
  7709.       else
  7710.         {
  7711.           /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
  7712.          A parameter is assumed not to have any side effects.
  7713.          If this should change for any reason, then this
  7714.          will have to wrap the bashed reference type in a save_expr.
  7715.          
  7716.          Also, if the parameter type is declared to be an X
  7717.          and there is an X(X&) constructor, we cannot lay it
  7718.          into the stack (any more), so we make this parameter
  7719.          look like it is really of reference type.  Functions
  7720.          which pass parameters to this function will know to
  7721.          create a temporary in their frame, and pass a reference
  7722.          to that.  */
  7723.  
  7724.           if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
  7725.           && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
  7726.         SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
  7727.  
  7728.           pushdecl (parm);
  7729.         }
  7730.  
  7731.       if (cleanup)
  7732.         {
  7733.           expand_decl (parm);
  7734.           expand_decl_cleanup (parm, cleanup);
  7735.           parms_have_cleanups = 1;
  7736.         }
  7737.     }
  7738.  
  7739.       /* Get the decls in their original chain order
  7740.      and record in the function.  */
  7741.       DECL_ARGUMENTS (fndecl) = getdecls ();
  7742.  
  7743.       storetags (chainon (parmtags, gettags ()));
  7744.     }
  7745.   else
  7746.     DECL_ARGUMENTS (fndecl) = 0;
  7747.  
  7748.   /* Now store the final chain of decls for the arguments
  7749.      as the decl-chain of the current lexical scope.
  7750.      Put the enumerators in as well, at the front so that
  7751.      DECL_ARGUMENTS is not modified.  */
  7752.  
  7753.   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  7754.  
  7755.   /* Initialize the RTL code for the function.  */
  7756.   DECL_SAVED_INSNS (fndecl) = 0;
  7757.   expand_function_start (fndecl, parms_have_cleanups);
  7758.  
  7759.   if (flag_handle_exceptions)
  7760.     {
  7761.       /* Make the throw decl visibile at this level, just
  7762.      not in the way of the parameters.  */
  7763.       pushdecl (eh_decl);
  7764.       expand_decl_init (eh_decl);
  7765.     }
  7766.  
  7767.   /* Create a binding contour which can be used to catch
  7768.      cleanup-generated temporaries.  Also, if the return value needs or
  7769.      has initialization, deal with that now.  */
  7770.   if (parms_have_cleanups)
  7771.     {
  7772.       pushlevel (0);
  7773.       expand_start_bindings (0);
  7774.     }
  7775.  
  7776.   current_function_parms_stored = 1;
  7777.  
  7778.   /* If this function is `main', emit a call to `__main'
  7779.      to run global initializers, etc.  */
  7780.   if (flag__main)
  7781.     if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  7782.     && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0)
  7783.       expand_expr (build_function_call (lookup_name (get_identifier ("__main")),
  7784.                     NULL_TREE),
  7785.            0, VOIDmode, 0);
  7786. }
  7787.  
  7788. /* Bind a name and initialization to the return value of
  7789.    the current function.  */
  7790. void
  7791. store_return_init (init)
  7792.      tree init;
  7793. {
  7794.   tree decl = DECL_RESULT (current_function_decl);
  7795.  
  7796.   /* Can't let this happen for constructors.  */
  7797.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  7798.     {
  7799.       error ("can't redefine default return value for constructors");
  7800.       return;
  7801.     }
  7802.  
  7803.   /* If we have a named return value, put that in our scope as well.  */
  7804.   if (DECL_NAME (decl) != value_identifier)
  7805.     {
  7806.       /* If this named return value comes in a register,
  7807.      put it in a pseudo-register.  */
  7808.       if (TREE_REGDECL (decl))
  7809.     {
  7810.       original_result_rtx = DECL_RTL (decl);
  7811.       DECL_RTL (decl) = (struct rtx_def *)gen_reg_rtx (DECL_MODE (decl));
  7812.     }
  7813.  
  7814.       /* Let `finish_decl' know that this initializer is ok.  */
  7815.       DECL_INITIAL (decl) = init;
  7816.       pushdecl (decl);
  7817.       finish_decl (decl, init, 0);
  7818.     }
  7819. }
  7820.  
  7821. /* Generate code for default X(X&) constructor.  */
  7822. static void
  7823. build_default_constructor (fndecl)
  7824.      tree fndecl;
  7825. {
  7826.   int i = CLASSTYPE_N_BASECLASSES (current_class_type);
  7827.   tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
  7828.   tree fields = TYPE_FIELDS (current_class_type);
  7829.   if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  7830.     parm = TREE_CHAIN (parm);
  7831.   parm = DECL_REFERENCE_SLOT (parm);
  7832.  
  7833.   while (i > 0)
  7834.     {
  7835.       tree basetype = CLASSTYPE_BASECLASS (current_class_type, i);
  7836.       if (TYPE_GETS_INIT_REF (basetype))
  7837.     {
  7838.       tree name = TYPE_NAME (basetype);
  7839.       if (TREE_CODE (name) == TYPE_DECL)
  7840.         name = DECL_NAME (name);
  7841.       current_base_init_list = tree_cons (name, parm, current_base_init_list);
  7842.     }
  7843.       i -= 1;
  7844.     }
  7845.   for (fields = TYPE_FIELDS (current_class_type); fields;
  7846.        fields = TREE_CHAIN (fields))
  7847.     {
  7848.       tree name, init;
  7849.       if (TREE_STATIC (fields))
  7850.     continue;
  7851.       if (TREE_CODE (fields) != FIELD_DECL)
  7852.     continue;
  7853.       if (DECL_NAME (fields))
  7854.     {
  7855.       if (VFIELD_NAME_P (DECL_NAME (fields)))
  7856.         continue;
  7857.       if (VBASE_NAME_P (DECL_NAME (fields)))
  7858.         continue;
  7859.  
  7860.       /* True for duplicate members.  */
  7861.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
  7862.         continue;
  7863.     }
  7864.  
  7865.       init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
  7866.  
  7867.       if (TREE_ANON_UNION_ELEM (fields))
  7868.     name = build (COMPONENT_REF, TREE_TYPE (fields), C_C_D, fields);
  7869.       else
  7870.     {
  7871.       name = DECL_NAME (fields);
  7872.       init = build_tree_list (NULL_TREE, init);
  7873.     }
  7874.  
  7875.       current_member_init_list
  7876.     = tree_cons (name, init, current_member_init_list);
  7877.     }
  7878. }
  7879.  
  7880.  
  7881. /* Finish up a function declaration and compile that function
  7882.    all the way to assembler language output.  The free the storage
  7883.    for the function definition.
  7884.  
  7885.    This is called after parsing the body of the function definition.
  7886.    LINENO is the current line number.
  7887.  
  7888.    C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
  7889.    (and expand_end_bindings) must be made to take care of the binding
  7890.    contour for the base initializers.  This is only relevant for
  7891.    constructors.  */
  7892.  
  7893. void
  7894. finish_function (lineno, call_poplevel)
  7895.      int lineno;
  7896.      int call_poplevel;
  7897. {
  7898.   register tree fndecl = current_function_decl;
  7899.   tree fntype = TREE_TYPE (fndecl), ctype = NULL_TREE;
  7900.   struct rtx_def *head, *last_parm_insn, *mark;
  7901.   extern struct rtx_def *get_last_insn ();
  7902.   extern struct rtx_def *cleanup_label, *return_label;
  7903.   extern int sets_exception_throw_decl;
  7904.   /* Label to use if this function is supposed to return a value.  */
  7905.   tree no_return_label = 0;
  7906.  
  7907. /*  TREE_READONLY (fndecl) = 1;
  7908.     This caused &foo to be of type ptr-to-const-function
  7909.     which then got a warning when stored in a ptr-to-function variable.  */
  7910.  
  7911.   /* This happens on strange parse errors.  */
  7912.   if (! current_function_parms_stored)
  7913.     {
  7914.       call_poplevel = 0;
  7915.       store_parm_decls ();
  7916.     }
  7917.  
  7918.   if (flag_minimal_debug
  7919.       && write_symbols == DBX_DEBUG
  7920.       && (TREE_CODE (fntype) != METHOD_TYPE
  7921.       || ! CLASSTYPE_ASM_WRITTEN (TYPE_METHOD_BASETYPE (fntype))))
  7922.     {
  7923.       tree ttype = target_type (fntype);
  7924.       tree parmdecl;
  7925.  
  7926.       if (IS_AGGR_TYPE (ttype))
  7927.     /* Let debugger know it should output info for this type.  */
  7928.     CLASSTYPE_ASM_WRITTEN (ttype) = 1;
  7929.  
  7930.       for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
  7931.     {
  7932.       ttype = target_type (TREE_TYPE (parmdecl));
  7933.       if (IS_AGGR_TYPE (ttype))
  7934.         /* Let debugger know it should output info for this type.  */
  7935.         CLASSTYPE_ASM_WRITTEN (ttype) = 1;
  7936.     }
  7937.     }
  7938.  
  7939.   /* Clean house because we will need to reorder insns here.  */
  7940.   do_pending_stack_adjust ();
  7941.  
  7942.   if (dtor_label)
  7943.     {
  7944.       tree cond = integer_one_node;
  7945.       tree exprstmt, vfields;
  7946.       tree in_charge_node = lookup_name (in_charge_identifier);
  7947.       int ok_to_optimize_dtor = 0;
  7948.  
  7949.       if (current_function_assigns_this)
  7950.     cond = build (NE_EXPR, integer_type_node,
  7951.               current_class_decl, integer_zero_node);
  7952.       else
  7953.     {
  7954.       int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
  7955.  
  7956.       /* If this destructor is empty, then we don't need to check
  7957.          whether `this' is NULL in some cases.  */
  7958.       mark = get_last_insn ();
  7959.       last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
  7960.  
  7961.       if ((flag_this_is_variable & 1) == 0)
  7962.         ok_to_optimize_dtor = 1;
  7963.       else if (mark == last_parm_insn)
  7964.         ok_to_optimize_dtor
  7965.           = (n_baseclasses == 0
  7966.          || (n_baseclasses == 1
  7967.              && TYPE_HAS_DESTRUCTOR (CLASSTYPE_BASECLASS (current_class_type, 1))));
  7968.     }
  7969.  
  7970.       /* These initializations might go inline.  Protect
  7971.      the binding level of the parms.  */
  7972.       pushlevel (0);
  7973.  
  7974.       if (current_function_assigns_this)
  7975.     {
  7976.       TYPE_ANY_ASSIGNS_THIS (current_class_type) = 1;
  7977.       current_function_assigns_this = 0;
  7978.       current_function_just_assigned_this = 0;
  7979.     }
  7980.  
  7981.       /* Generate the code to call destructor on base class.
  7982.      If this destructor belongs to a class with virtual
  7983.      functions, then set the virtual function table
  7984.      pointer to represent the type of our base class.  */
  7985.  
  7986.       /* This side-effect makes call to `build_delete' generate the
  7987.      code we have to have at the end of this destructor.  */
  7988.       TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
  7989.  
  7990.       /* These are two cases where we cannot delegate deletion.  */
  7991.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
  7992.       || TREE_GETS_DELETE (current_class_type))
  7993.     exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
  7994.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  7995.       else
  7996.     exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
  7997.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  7998.  
  7999.       /* If we did not assign to this, then `this' is non-zero at
  8000.      the end of a destructor.  As a special optimization, don't
  8001.      emit test if this is an empty destructor.  If it does nothing,
  8002.      it does nothing.  If it calls a base destructor, the base
  8003.      destructor will perform the test.  */
  8004.  
  8005.       if (exprstmt != error_mark_node
  8006.       && (TREE_CODE (exprstmt) != NOP_EXPR
  8007.           || TREE_OPERAND (exprstmt, 0) != integer_zero_node
  8008.           || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
  8009.     {
  8010.       expand_label (dtor_label);
  8011.       if (cond != integer_one_node)
  8012.         expand_start_cond (cond, 0);
  8013.       expand_expr_stmt (exprstmt);
  8014.  
  8015.       /* Run destructor on all virtual baseclasses.  */
  8016.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  8017.         {
  8018.           tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
  8019.           expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
  8020.                     in_charge_node, integer_two_node), 0);
  8021.           while (vbases)
  8022.         {
  8023.           if (TYPE_NEEDS_DESTRUCTOR (TREE_VALUE (vbases)))
  8024.             {
  8025.               tree ptr = convert_pointer_to_vbase (TREE_TYPE (vbases), current_class_decl);
  8026.               expand_expr_stmt (build_delete (TYPE_POINTER_TO (TREE_VALUE (vbases)),
  8027.                               ptr, integer_zero_node,
  8028.                               LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
  8029.             }
  8030.           vbases = TREE_CHAIN (vbases);
  8031.         }
  8032.           expand_end_cond ();
  8033.         }
  8034.  
  8035.       do_pending_stack_adjust ();
  8036.       if (cond != integer_one_node)
  8037.         expand_end_cond ();
  8038.     }
  8039.  
  8040.       TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
  8041.  
  8042.       /* At the end, call delete if that's what's requested.  */
  8043.       if (TREE_GETS_DELETE (current_class_type))
  8044.     /* This NOP_EXPR means we are in a static call context.  */
  8045.     exprstmt = build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node),
  8046.                       get_identifier (OPERATOR_DELETE_FORMAT),
  8047.                       build_tree_list (NULL_TREE, current_class_decl),
  8048.                       NULL_TREE, LOOKUP_NORMAL);
  8049.       else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  8050.     exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0);
  8051.       else
  8052.     exprstmt = 0;
  8053.  
  8054.       if (exprstmt)
  8055.     {
  8056.       cond = build (BIT_AND_EXPR, integer_type_node,
  8057.             in_charge_node, integer_one_node);
  8058.       expand_start_cond (cond, 0);
  8059.       expand_expr_stmt (exprstmt);
  8060.       expand_end_cond ();
  8061.     }
  8062.  
  8063.       /* End of destructor.  */
  8064.       poplevel (2, 0, 0);
  8065.  
  8066.       /* Back to the top of destructor.  */
  8067.       /* Dont execute destructor code if `this' is NULL.  */
  8068.       mark = get_last_insn ();
  8069.       last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
  8070.       if (last_parm_insn == 0) last_parm_insn = mark;
  8071.       else last_parm_insn = (struct rtx_def *) previous_insn (last_parm_insn);
  8072.  
  8073.       /* Make all virtual function table pointers point to CURRENT_CLASS_TYPE's
  8074.      virtual function tables.  */
  8075.       if (CLASSTYPE_VFIELDS (current_class_type))
  8076.     {
  8077.       for (vfields = CLASSTYPE_VFIELDS (current_class_type);
  8078.            TREE_CHAIN (vfields);
  8079.            vfields = TREE_CHAIN (vfields))
  8080.         expand_expr_stmt (build_virtual_init (current_class_type,
  8081.                           TREE_VALUE (vfields),
  8082.                           current_class_decl));
  8083.       expand_expr_stmt (build_virtual_init (current_class_type,
  8084.                         current_class_type,
  8085.                         current_class_decl));
  8086.     }
  8087.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  8088.     expand_expr_stmt (build_vbase_vtables_init (current_class_type,
  8089.                             current_class_type,
  8090.                             C_C_D, current_class_decl, 0));
  8091.       if (! ok_to_optimize_dtor)
  8092.     {
  8093.       cond = build_binary_op (NE_EXPR, current_class_decl, integer_zero_node);
  8094.       expand_start_cond (cond, 0);
  8095.     }
  8096.       if (mark != get_last_insn ())
  8097.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  8098.       if (! ok_to_optimize_dtor)
  8099.       expand_end_cond ();
  8100.     }
  8101.   else if (current_function_assigns_this)
  8102.     {
  8103.       /* Does not need to call emit_base_init, because
  8104.      that is done (if needed) just after assignment to this
  8105.      is seen.  */
  8106.  
  8107.       TYPE_ANY_ASSIGNS_THIS (current_class_type) = 1;
  8108.  
  8109.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  8110.     {
  8111.       expand_label (ctor_label);
  8112.       ctor_label = NULL_TREE;
  8113.  
  8114.       if (call_poplevel)
  8115.         {
  8116.           tree decls = getdecls ();
  8117.           if (flag_handle_exceptions == 2)
  8118.         deactivate_exception_cleanups ();
  8119.           expand_end_bindings (decls, decls != 0, 0);
  8120.           poplevel (decls != 0, 0, 0);
  8121.         }
  8122.       c_expand_return (current_class_decl);
  8123.     }
  8124.       else if (DECL_RESULT (current_function_decl))
  8125.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  8126.  
  8127.       current_function_assigns_this = 0;
  8128.       current_function_just_assigned_this = 0;
  8129.       base_init_insns = 0;
  8130.     }
  8131.   else if (DECL_CONSTRUCTOR_P (fndecl))
  8132.     {
  8133.       tree allocated_this;
  8134.       tree cond, thenclause;
  8135.       /* Allow constructor for a type to get a new instance of the object
  8136.      using `build_new'.  */
  8137.       tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
  8138.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
  8139.  
  8140.       DECL_RETURNS_FIRST_ARG (fndecl) = 1;
  8141.  
  8142.       if (flag_this_is_variable)
  8143.     {
  8144.       cond = build_binary_op (EQ_EXPR, current_class_decl, integer_zero_node);
  8145.       thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
  8146.                       build_new (NULL_TREE, current_class_type, void_type_node, 0));
  8147.       if (flag_handle_exceptions == 2)
  8148.         {
  8149.           tree cleanup, cleanup_deallocate;
  8150.  
  8151.           allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node);
  8152.           TREE_REGDECL (allocated_this) = 1;
  8153.           DECL_INITIAL (allocated_this) = error_mark_node;
  8154.           expand_decl (allocated_this);
  8155.           expand_decl_init (allocated_this);
  8156.           /* How we cleanup `this' if an exception was raised before
  8157.          we are ready to bail out.  */
  8158.           cleanup = TREE_GETS_DELETE (current_class_type)
  8159.         ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this)
  8160.           : build_delete (TREE_TYPE (allocated_this), allocated_this, integer_three_node, LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1);
  8161.           cleanup_deallocate
  8162.         = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node);
  8163.           cleanup = tree_cons (NULL_TREE, cleanup,
  8164.                    build_tree_list (NULL_TREE, cleanup_deallocate));
  8165.  
  8166.           expand_decl_cleanup (allocated_this,
  8167.                    build (COND_EXPR, integer_type_node,
  8168.                       build (NE_EXPR, integer_type_node,
  8169.                          allocated_this, integer_zero_node),
  8170.                       build_compound_expr (cleanup),
  8171.                       integer_zero_node));
  8172.         }
  8173.     }
  8174.       else if (TREE_GETS_NEW (current_class_type))
  8175.     /* Just check visibility here.  */
  8176.     build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node),
  8177.                get_identifier (OPERATOR_NEW_FORMAT),
  8178.                build_tree_list (NULL_TREE, integer_zero_node),
  8179.                NULL_TREE, LOOKUP_NORMAL);
  8180.  
  8181.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
  8182.  
  8183.       /* must keep the first insn safe.  */
  8184.       head = (struct rtx_def *)get_insns ();
  8185.  
  8186.       /* this note will come up to the top with us.  */
  8187.       mark = get_last_insn ();
  8188.  
  8189.       if (flag_this_is_variable)
  8190.     {
  8191.       expand_start_cond (cond, 0);
  8192.       expand_expr_stmt (thenclause);
  8193.       if (flag_handle_exceptions == 2)
  8194.         expand_assignment (allocated_this, current_class_decl, 0, 0);
  8195.       expand_end_cond ();
  8196.     }
  8197.  
  8198.       if (DECL_COMPILER_GENERATED_P (fndecl)
  8199.       && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
  8200.     build_default_constructor (fndecl);
  8201.  
  8202.       /* Emit insns from `emit_base_init' which sets up virtual
  8203.      function table pointer(s).  */
  8204.       emit_insns (base_init_insns);
  8205.       base_init_insns = 0;
  8206.  
  8207.       /* This is where the body of the constructor begins.
  8208.      If there were no insns in this function body, then the
  8209.      last_parm_insn is also the last insn.
  8210.  
  8211.      If optimization is enabled, last_parm_insn may move, so
  8212.      we don't hold on to it (across emit_base_init).  */
  8213.       last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
  8214.       if (last_parm_insn == 0) last_parm_insn = mark;
  8215.       else last_parm_insn = (struct rtx_def *) previous_insn (last_parm_insn);
  8216.  
  8217.       if (mark != get_last_insn ())
  8218.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  8219.  
  8220.       /* This is where the body of the constructor ends.  */
  8221.       expand_label (ctor_label);
  8222.       ctor_label = NULL_TREE;
  8223.       if (flag_handle_exceptions == 2)
  8224.     {
  8225.       expand_assignment (allocated_this, integer_zero_node, 0, 0);
  8226.       deactivate_exception_cleanups ();
  8227.     }
  8228.  
  8229.       pop_implicit_try_blocks (NULL_TREE);
  8230.  
  8231.       if (call_poplevel)
  8232.     {
  8233.       expand_end_bindings (getdecls (), 1, 0);
  8234.       poplevel (1, 1, 0);
  8235.     }
  8236.  
  8237.       c_expand_return (current_class_decl);
  8238.  
  8239.       current_function_assigns_this = 0;
  8240.       current_function_just_assigned_this = 0;
  8241.     }
  8242.   else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  8243.        && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main"))
  8244.     {
  8245.       /* Make it so that `main' always returns 0 by default.  */
  8246. #ifdef VMS
  8247.       c_expand_return (integer_one_node);
  8248. #else
  8249.       c_expand_return (integer_zero_node);
  8250. #endif
  8251.     }
  8252.   else if (DECL_RESULT (current_function_decl))
  8253.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  8254.  
  8255.   /* That's the end of the vtable decl's life.  Need to mark it such
  8256.      if doing stupid register allocation.
  8257.  
  8258.      Note that current_vtable_decl is really an INDIRECT_REF
  8259.      on top of a VAR_DECL here.  */
  8260.   if (obey_regdecls && current_vtable_decl)
  8261.     use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
  8262.  
  8263.   /* If this function is supposed to return a value, ensure that
  8264.      we do not fall into the cleanups by mistake.  The end of our
  8265.      function will look like this:
  8266.  
  8267.     user code (may have return stmt somewhere)
  8268.     goto no_return_label
  8269.     cleanup_label:
  8270.     cleanups
  8271.     goto return_label
  8272.     no_return_label:
  8273.     NOTE_INSN_FUNCTION_END
  8274.     return_label:
  8275.     things for return
  8276.  
  8277.      If the user omits a return stmt in the USER CODE section, we
  8278.      will have a control path which reaches NOTE_INSN_FUNCTION_END.
  8279.      Otherwise, we won't.  */
  8280.   if (no_return_label)
  8281.     {
  8282.       DECL_CONTEXT (no_return_label) = fndecl;
  8283.       DECL_INITIAL (no_return_label) = error_mark_node;
  8284.       DECL_SOURCE_FILE (no_return_label) = input_filename;
  8285.       DECL_SOURCE_LINE (no_return_label) = lineno;
  8286.       expand_goto (no_return_label);
  8287.     }
  8288.  
  8289.   if (cleanup_label)
  8290.     {
  8291.       /* remove the binding contour which is used
  8292.      to catch cleanup-generated temporaries.  */
  8293.       expand_end_bindings (0, 0, 0);
  8294.       poplevel (0, 0, 0);
  8295.     }
  8296.  
  8297.   /* Must mark the RESULT_DECL as being in this function.  */
  8298.  
  8299.   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
  8300.  
  8301.   /* Obey `register' declarations if `setjmp' is called in this fn.  */
  8302.   if (flag_traditional && current_function_calls_setjmp)
  8303.     setjmp_protect (DECL_INITIAL (fndecl));
  8304.  
  8305.   if (cleanup_label)
  8306.     {
  8307.       /* Emit label at beginning of cleanup code for parmeters.  */
  8308.       emit_label (cleanup_label);
  8309.       /* After this point we zero out CLEANUP_LABEL so that all
  8310.      other `returns' go to RETURN_LABEL.  */
  8311.       cleanup_label = 0;
  8312.     }
  8313.  
  8314. #if 1
  8315.   /* Cheap hack to get better code from GNU C++.  Remove when cse is fixed.  */
  8316.   if (exception_throw_decl && sets_exception_throw_decl == 0)
  8317.     expand_assignment (exception_throw_decl, integer_zero_node, 0, 0);
  8318. #endif
  8319.  
  8320.   if (flag_handle_exceptions)
  8321.     {
  8322.       expand_end_try ();
  8323.       expand_start_except (0, 0);
  8324.       expand_end_except ();
  8325.     }
  8326.   expand_end_bindings (0, 0, 0);
  8327.  
  8328.   /* Get return value into reigster if that's where it's supposed to be.  */
  8329.   if (original_result_rtx)
  8330.     fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
  8331.  
  8332.   /* Finish building code that will trigger warnings if users forget
  8333.      to make their functions return values.  */
  8334.   if (no_return_label)
  8335.     {
  8336.       expand_null_return ();
  8337.       expand_label (no_return_label);
  8338.     }
  8339.  
  8340.   /* reset scope for C++: if we were in the scope of a class,
  8341.      then when we finish this function, we are not longer so.
  8342.      This cannot be done until we know for sure that no more
  8343.      class members will ever be referenced in this function
  8344.      (i.e., calls to destructors).  */
  8345.   if (current_class_name)
  8346.     {
  8347.       ctype = current_class_type;
  8348.       popclass (1);
  8349.     }
  8350.   else
  8351.     pop_memoized_context (1);
  8352.  
  8353.   /* Forget about all overloaded functions defined in
  8354.      this scope which go away.  */
  8355.   while (overloads_to_forget)
  8356.     {
  8357.       IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget))
  8358.     = TREE_VALUE (overloads_to_forget);
  8359.       overloads_to_forget = TREE_CHAIN (overloads_to_forget);
  8360.     }
  8361.  
  8362.   /* Generate rtl for function exit.  */
  8363.   expand_function_end (input_filename, lineno);
  8364.  
  8365.   /* This must come after expand_function_end because cleanups might
  8366.      have declarations (from inline functions) that need to go into
  8367.      this function's blocks.  */
  8368.   assert (current_binding_level->parm_flag == 1);
  8369.   poplevel (1, 0, 1);
  8370.  
  8371.   /* So we can tell if jump_optimize sets it to 1.  */
  8372.   current_function_returns_null = 0;
  8373.  
  8374.   if (TREE_EXTERNAL (fndecl) && ! TREE_PUBLIC (fndecl)
  8375.       /* This function is just along for the ride.  If we can make
  8376.      it inline, that's great.  Otherwise, just punt it.  */
  8377.       && (TREE_INLINE (fndecl) == 0
  8378.       || flag_no_inline
  8379.       || function_cannot_inline_p (fndecl)))
  8380.     {
  8381.       extern int rtl_dump_and_exit;
  8382.       int old_rtl_dump_and_exit = rtl_dump_and_exit;
  8383.       int inline_spec = TREE_INLINE (fndecl);
  8384.  
  8385.       /* This throws away the code for FNDECL.  */
  8386.       rtl_dump_and_exit = 1;
  8387.       /* This throws away the memory of the code for FNDECL.  */
  8388.       if (flag_no_inline)
  8389.     TREE_INLINE (fndecl) = 0;
  8390.       rest_of_compilation (fndecl);
  8391.       rtl_dump_and_exit = old_rtl_dump_and_exit;
  8392.       TREE_INLINE (fndecl) = inline_spec;
  8393.     }
  8394.   else
  8395.     /* Run the optimizers and output the assembler code for this function.  */
  8396.     rest_of_compilation (fndecl);
  8397.  
  8398.   if (ctype && TREE_ASM_WRITTEN (fndecl))
  8399.     CLASSTYPE_ASM_WRITTEN (ctype) = 1;
  8400.  
  8401.   /* Since we don't normally go through c_expand_return for constructors,
  8402.      this normally gets the wrong value.
  8403.      Also, named return values have their return codes emitted after
  8404.      NOTE_INSN_FUNCTION_END, confusing jump.c.  */
  8405.   if (DECL_CONSTRUCTOR_P (fndecl)
  8406.       || DECL_NAME (DECL_RESULT (fndecl)) != value_identifier)
  8407.     current_function_returns_null = 0;
  8408.  
  8409.   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
  8410.     warning ("`volatile' function does return");
  8411.   else if (warn_return_type && current_function_returns_null
  8412.        && TREE_TYPE (fntype) != void_type_node)
  8413.     /* If this function returns non-void and control can drop through,
  8414.        complain.  */
  8415.     warning ("control reaches end of non-void function");
  8416.   /* With just -W, complain only if function returns both with
  8417.      and without a value.  */
  8418.   else if (extra_warnings
  8419.        && current_function_returns_value && current_function_returns_null)
  8420.     warning ("this function may return with or without a value");
  8421.  
  8422.   /* Free all the tree nodes making up this function.  */
  8423.   /* Switch back to allocating nodes permanently
  8424.      until we start another function.  */
  8425.   permanent_allocation ();
  8426.  
  8427.   if (DECL_SAVED_INSNS (fndecl) == 0)
  8428.     {
  8429.       /* Stop pointing to the local nodes about to be freed.  */
  8430.       /* But DECL_INITIAL must remain nonzero so we know this
  8431.      was an actual function definition.  */
  8432.       DECL_INITIAL (fndecl) = error_mark_node;
  8433.       if (! DECL_CONSTRUCTOR_P (fndecl)
  8434.       || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
  8435.     DECL_ARGUMENTS (fndecl) = 0;
  8436.     }
  8437.  
  8438.   /* Let the error reporting routines know that we're outside a function.  */
  8439.   current_function_decl = NULL_TREE;
  8440.   named_label_uses = NULL_TREE;
  8441.   clear_anon_parm_name ();
  8442. }
  8443.  
  8444. /* Create the FUNCTION_DECL for a function definition.
  8445.    LINE1 is the line number that the definition absolutely begins on.
  8446.    LINE2 is the line number that the name of the function appears on.
  8447.    DECLSPECS and DECLARATOR are the parts of the declaration;
  8448.    they describe the function's name and the type it returns,
  8449.    but twisted together in a fashion that parallels the syntax of C.
  8450.  
  8451.    This function creates a binding context for the function body
  8452.    as well as setting up the FUNCTION_DECL in current_function_decl.
  8453.  
  8454.    Returns a FUNCTION_DECL on success.
  8455.  
  8456.    If the DECLARATOR is not suitable for a function (it defines a datum
  8457.    instead), we return 0, which tells yyparse to report a parse error.
  8458.  
  8459.    May return void_type_node indicating that this method is actually
  8460.    a friend.  See grokfield for more details.
  8461.  
  8462.    Came here with a `.pushlevel' .
  8463.  
  8464.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  8465.    CHANGES TO CODE IN `grokfield'.  */
  8466. tree
  8467. start_method (declspecs, declarator, raises)
  8468.      tree declarator, declspecs, raises;
  8469. {
  8470.   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
  8471.  
  8472.   /* Something too ugly to handle.  */
  8473.   if (fndecl == 0)
  8474.     return 0;
  8475.  
  8476.   /* Pass friends other than inline friend functions back.  */
  8477.   if (fndecl == void_type_node)
  8478.     return void_type_node;
  8479.  
  8480.   if (TREE_CODE (fndecl) != FUNCTION_DECL)
  8481.     /* Not a function, tell parser to report parse error.  */
  8482.     return 0;
  8483.  
  8484.   if (DECL_IN_AGGR_P (fndecl))
  8485.     {
  8486.       if (IDENTIFIER_ERROR_LOCUS (DECL_NAME (fndecl)) != current_class_type)
  8487.     error_with_decl (fndecl, "`%s' is already defined in aggregate scope");
  8488.       return void_type_node;
  8489.     }
  8490.  
  8491.   if (flag_default_inline)
  8492.     TREE_INLINE (fndecl) = 1;
  8493.  
  8494.   /* We read in the parameters on the maybepermanent_obstack,
  8495.      but we won't be getting back to them until after we
  8496.      may have clobbered them.  So the call to preserve_data
  8497.      will keep them safe.  */
  8498.   preserve_data ();
  8499.  
  8500.   if (! DECL_FRIEND_P (fndecl))
  8501.     {
  8502.       if (TREE_CHAIN (fndecl) != NULL_TREE)
  8503.     /* Need a fresh node here so that we don't get circularity
  8504.        when we link these together.  If FNDECL was a friend, then
  8505.        `pushdecl' does the right thing, which is nothing wrt its
  8506.        current value of TREE_CHAIN.  */
  8507.     fndecl = copy_node (fndecl);
  8508.  
  8509.       if (DECL_CONSTRUCTOR_P (fndecl))
  8510.     grok_ctor_properties (current_class_type, fndecl);
  8511.       else if (OPERATOR_NAME_P (DECL_NAME (fndecl)))
  8512.     {
  8513.       TREE_OPERATOR (fndecl) = 1;
  8514.       grok_op_properties (fndecl);
  8515.     }
  8516.     }
  8517.  
  8518.   finish_decl (fndecl, NULL, NULL);
  8519.  
  8520.   /* Make a place for the parms */
  8521.   pushlevel (0);
  8522.   current_binding_level->parm_flag = 1;
  8523.   
  8524.   DECL_IN_AGGR_P (fndecl) = 1;
  8525.   return fndecl;
  8526. }
  8527.  
  8528. /* Go through the motions of finishing a function definition.
  8529.    We don't compile this method until after the whole class has
  8530.    been processed.
  8531.  
  8532.    FINISH_METHOD must return something that looks as though it
  8533.    came from GROKFIELD (since we are defining a method, after all).
  8534.  
  8535.    This is called after parsing the body of the function definition.
  8536.    STMTS is the chain of statements that makes up the function body.
  8537.  
  8538.    DECL is the ..._DECL that `start_method' provided.  */
  8539.  
  8540. tree
  8541. finish_method (decl)
  8542.      tree decl;
  8543. {
  8544.   register tree fndecl = decl;
  8545.   tree old_initial;
  8546.  
  8547.   register tree link;
  8548.  
  8549.   if (decl == void_type_node)
  8550.     return decl;
  8551.  
  8552.   old_initial = DECL_INITIAL (fndecl);
  8553.  
  8554.   /* Undo the level for the parms (from start_method).
  8555.      This is like poplevel, but it causes nothing to be
  8556.      saved.  Saving information here confuses symbol-table
  8557.      output routines.  Besides, this information will
  8558.      be correctly output when this method is actually
  8559.      compiled.  */
  8560.  
  8561.   /* Clear out the meanings of the local variables of this level;
  8562.      also record in each decl which block it belongs to.  */
  8563.  
  8564.   for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
  8565.     {
  8566.       if (DECL_NAME (link) != 0)
  8567.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  8568.       DECL_CONTEXT (link) = 0;
  8569.     }
  8570.  
  8571.   /* Restore all name-meanings of the outer levels
  8572.      that were shadowed by this level.  */
  8573.  
  8574.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  8575.       IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  8576.   for (link = current_binding_level->class_shadowed;
  8577.        link;
  8578.        link = TREE_CHAIN (link))
  8579.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  8580.  
  8581. #ifdef FIELD_XREF
  8582.   FIELD_xref_end_scope(current_binding_level,
  8583.                current_binding_level->level_chain,
  8584.                current_binding_level->parm_flag,
  8585.                current_binding_level->keep,
  8586.                current_binding_level->tag_transparent);
  8587. #endif
  8588.  
  8589.   POP_BINDING_LEVEL;
  8590.  
  8591.   DECL_INITIAL (fndecl) = old_initial;
  8592.   if (DECL_FRIEND_P (fndecl))
  8593.     {
  8594.       if (current_lang_name == lang_name_cplusplus)
  8595.     CLASSTYPE_INLINE_FRIENDS (current_class_type)
  8596.       = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
  8597.       return void_type_node;
  8598.     }
  8599.   return decl;
  8600. }
  8601.  
  8602. /* Called when a new struct TYPE is defined.
  8603.    If this structure or union completes the type of any previous
  8604.    variable declaration, lay it out and output its rtl.  */
  8605.  
  8606. void
  8607. hack_incomplete_structures (type)
  8608.      tree type;
  8609. {
  8610.   tree decl;
  8611.  
  8612.   if (current_binding_level->n_incomplete == 0)
  8613.     return;
  8614.  
  8615.   for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
  8616.     if (TREE_TYPE (decl) == type
  8617.     || (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  8618.         && TREE_TYPE (TREE_TYPE (decl)) == type))
  8619.       {
  8620.     if (TREE_CODE (decl) == TYPE_DECL)
  8621.       layout_type (TREE_TYPE (decl));
  8622.     else
  8623.       {
  8624.         int toplevel = global_binding_level == current_binding_level;
  8625.         layout_decl (decl, 0);
  8626.         rest_of_decl_compilation (decl, 0, toplevel, 0);
  8627.         if (! toplevel)
  8628.           {
  8629.         expand_decl (decl);
  8630.         expand_decl_cleanup (decl, maybe_build_cleanup (decl));
  8631.         expand_decl_init (decl);
  8632.           }
  8633.       }
  8634.     --current_binding_level->n_incomplete;
  8635.     assert (current_binding_level->n_incomplete >= 0);
  8636.       }
  8637. }
  8638.  
  8639. /* Nonzero if presently building a cleanup.  Needed because
  8640.    SAVE_EXPRs are not the right things to use inside of cleanups.
  8641.    They are only ever evaluated once, where the cleanup
  8642.    might be evaluated several times.  In this case, a later evaluation
  8643.    of the cleanup might fill in the SAVE_EXPR_RTL, and it will
  8644.    not be valid for an earlier cleanup.  */
  8645.  
  8646. int building_cleanup;
  8647.  
  8648. /* If DECL is of a type which needs a cleanup, build that cleanup here.
  8649.    We don't build cleanups if just going for syntax checking, since
  8650.    fixup_cleanups does not know how to not handle them.
  8651.  
  8652.    Don't build these on the momentary obstack; they must live
  8653.    the life of the binding contour.  */
  8654. tree
  8655. maybe_build_cleanup (decl)
  8656.      tree decl;
  8657. {
  8658.   tree type = TREE_TYPE (decl);
  8659.   if (TYPE_NEEDS_DESTRUCTOR (type))
  8660.     {
  8661.       int temp;
  8662.       tree rval;
  8663.       int old_building_cleanup = building_cleanup;
  8664.       building_cleanup = 1;
  8665.       if (TREE_CODE (decl) == PARM_DECL)
  8666.     {
  8667.       temp = allocation_temporary_p ();
  8668.       end_temporary_allocation ();
  8669.     }
  8670.       else
  8671.     temp = suspend_momentary ();
  8672.  
  8673.       if (TREE_CODE (type) == ARRAY_TYPE)
  8674.     rval = decl;
  8675.       else
  8676.     {
  8677.       mark_addressable (decl);
  8678.       rval = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
  8679.     }
  8680.       rval = build_delete (TREE_TYPE (rval), rval, integer_two_node,
  8681.                LOOKUP_NORMAL, 0);
  8682.  
  8683.       if (TYPE_LANG_SPECIFIC (type)
  8684.       && ! TYPE_HAS_DESTRUCTOR (type)
  8685.       && TYPE_USES_VIRTUAL_BASECLASSES (type))
  8686.     rval = build_compound_expr (tree_cons (NULL_TREE, rval,
  8687.                            build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
  8688.  
  8689.       current_binding_level->have_cleanups = 1;
  8690.       current_binding_level->more_exceptions_ok = 0;
  8691.  
  8692.       if (TREE_CODE (decl) == PARM_DECL)
  8693.     {
  8694.       if (temp)
  8695.         resume_temporary_allocation ();
  8696.     }
  8697.       else
  8698.     resume_momentary (temp);
  8699.  
  8700.       building_cleanup = old_building_cleanup;
  8701.  
  8702.       return rval;
  8703.     }
  8704.   return 0;
  8705. }
  8706.  
  8707. tree
  8708. cleanup_after_call (expr)
  8709.      tree expr;
  8710. {
  8711.   tree type = TREE_TYPE (expr);
  8712.   tree decl = get_temp_name (type, 0);
  8713.   tree rval = build (WITH_CLEANUP_EXPR, type,
  8714.              build (INIT_EXPR, type, decl, expr), 0,
  8715.              maybe_build_cleanup (decl));
  8716.   return rval;
  8717. }
  8718.  
  8719. /* Expand a C++ expression at the statement level.
  8720.    This is needed to ferret out nodes which have UNKNOWN_TYPE.
  8721.    The C++ type checker should get all of these out when
  8722.    expressions are combined with other, type-providing, expressions,
  8723.    leaving only orphan expressions, such as:
  8724.  
  8725.    &class::bar;        / / takes its address, but do nothing with it.
  8726.  
  8727.    */
  8728. void
  8729. cplus_expand_expr_stmt (exp)
  8730.      tree exp;
  8731. {
  8732.   if (TREE_TYPE (exp) == unknown_type_node)
  8733.     {
  8734.       if (TREE_CODE (exp) == ADDR_EXPR)
  8735.     {
  8736.       if (TREE_CODE (TREE_OPERAND (exp, 0)) == OP_IDENTIFIER)
  8737.         error ("unresolved reference to user-defined operator");
  8738.       else
  8739.         error ("address of overloaded function with no contextual type information");
  8740.     }
  8741.       else if (TREE_CODE (exp) == TREE_LIST)
  8742.     error ("address of overloaded function with no contextual type information");
  8743.       else if (TREE_CODE (exp) == OP_IDENTIFIER)
  8744.     error ("unresolved reference to user-defined operator");
  8745.       else if (TREE_CODE (exp) == COMPONENT_REF)
  8746.     warning ("useless reference to a member function name, did you forget the ()?");
  8747.     }
  8748.   else
  8749.     {
  8750.       int remove_implicit_immediately = 0;
  8751.  
  8752.       if (TREE_CODE (exp) == CALL_EXPR
  8753.       && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (exp)))
  8754.     exp = cleanup_after_call (exp);
  8755.       else if (TREE_CODE (exp) == FUNCTION_DECL)
  8756.     warning_with_decl (exp, "reference, not call, to function `%s'");
  8757.       if (TREE_RAISES (exp))
  8758.     {
  8759.       assert (flag_handle_exceptions);
  8760.       if (flag_handle_exceptions == 2)
  8761.         {
  8762.           if (! current_binding_level->more_exceptions_ok)
  8763.         {
  8764.           extern struct nesting *nesting_stack, *block_stack;
  8765.  
  8766.           remove_implicit_immediately
  8767.             = (nesting_stack != block_stack);
  8768.           cplus_expand_start_try (1);
  8769.         }
  8770.           current_binding_level->have_exceptions = 1;
  8771.         }
  8772.     }
  8773.       expand_expr_stmt (exp);
  8774.       if (remove_implicit_immediately)
  8775.     pop_implicit_try_blocks (NULL_TREE);
  8776.     }
  8777.  
  8778.   /* Clean up any pending cleanups.  This happens when a function call
  8779.      returns a cleanup-needing value that nobody uses.  */
  8780.   expand_cleanups_to (NULL_TREE);
  8781. }
  8782.  
  8783. /* When a stmt has been parsed, this function is called.
  8784.  
  8785.    Currently, this function only does something within a
  8786.    constructor's scope: if a stmt has just assigned to this,
  8787.    and we are in a derived class, we call `emit_base_init'.  */
  8788.  
  8789. void
  8790. finish_stmt ()
  8791. {
  8792.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  8793.  
  8794.   
  8795.   if (current_function_assigns_this
  8796.       || ! current_function_just_assigned_this)
  8797.     return;
  8798.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  8799.     {
  8800.       /* Constructors must wait until we are out of control
  8801.      zones before calling base constructors.  */
  8802.       if (cond_stack || loop_stack || case_stack)
  8803.     return;
  8804.       emit_insns (base_init_insns);
  8805.       check_base_init (current_class_type);
  8806.     }
  8807.   current_function_assigns_this = 1;
  8808. }
  8809.  
  8810. void
  8811. pop_implicit_try_blocks (decl)
  8812.      tree decl;
  8813. {
  8814.   if (decl)
  8815.     {
  8816.       assert (current_binding_level->parm_flag == 3);
  8817.       current_binding_level->names = TREE_CHAIN (decl);
  8818.     }
  8819.  
  8820.   while (current_binding_level->parm_flag == 3)
  8821.     {
  8822.       tree name = get_identifier ("(compiler error)");
  8823.       tree orig_ex_type = current_exception_type;
  8824.       tree orig_ex_decl = current_exception_decl;
  8825.       tree orig_ex_obj = current_exception_object;
  8826.       tree decl = cplus_expand_end_try (2), decls;
  8827.       tree current_exception_ptr;
  8828.  
  8829.       /* @@ It would be nice to make all these point
  8830.      to exactly the same handler.  */
  8831.       /* Start hidden EXCEPT.  */
  8832.       cplus_expand_start_except (name, decl);
  8833.       /* reraise ALL.  */
  8834.       cplus_expand_reraise (NULL_TREE);
  8835.       current_exception_type = orig_ex_type;
  8836.       current_exception_decl = orig_ex_decl;
  8837.       current_exception_object = orig_ex_obj;
  8838.       /* This will reraise for us.  */
  8839.       cplus_expand_end_except (error_mark_node);
  8840.     }
  8841.  
  8842.   if (decl)
  8843.     {
  8844.       TREE_CHAIN (decl) = current_binding_level->names;
  8845.       current_binding_level->names = decl;
  8846.     }
  8847. }
  8848.  
  8849. #ifdef FIELD_XREF
  8850. static void
  8851. FIELD_end_scope(lvl)
  8852.    struct binding_level * lvl;
  8853. {
  8854.    FIELD_xref_end_scope(lvl,
  8855.             lvl->level_chain,
  8856.             lvl->parm_flag,
  8857.             lvl->keep,
  8858.             lvl->tag_transparent);
  8859. };
  8860.  
  8861. #endif
  8862.  
  8863. /* Push a cleanup onto the current binding contour that will cause
  8864.    ADDR to be cleaned up, in the case that an exception propagates
  8865.    through its binding contour.  */
  8866.  
  8867. void
  8868. push_exception_cleanup (addr)
  8869.      tree addr;
  8870. {
  8871.   tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node);
  8872.   tree cleanup;
  8873.  
  8874.   decl = pushdecl (decl);
  8875.   TREE_REGDECL (decl) = 1;
  8876.   store_init_value (decl, addr);
  8877.   expand_decl (decl);
  8878.   expand_decl_init (decl);
  8879.  
  8880.   cleanup = build (COND_EXPR, integer_type_node,
  8881.            build (NE_EXPR, integer_type_node,
  8882.               decl, integer_zero_node),
  8883.            build_delete (TREE_TYPE (addr), decl,
  8884.                  lookup_name (in_charge_identifier),
  8885.                  LOOKUP_NORMAL, 0),
  8886.            integer_zero_node);
  8887.   expand_decl_cleanup (decl, cleanup);
  8888. }
  8889.  
  8890. /* For each binding contour, emit code that deactivates the
  8891.    exception cleanups.  All other cleanups are left as they were.  */
  8892.  
  8893. static void
  8894. deactivate_exception_cleanups ()
  8895. {
  8896.   struct binding_level *b = current_binding_level;
  8897.   tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME);
  8898.   while (b != class_binding_level)
  8899.     {
  8900.       if (b->parm_flag == 3)
  8901.     {
  8902.       tree decls = b->names;
  8903.       while (decls)
  8904.         {
  8905.           if (DECL_NAME (decls) == xyzzy)
  8906.         expand_assignment (decls, integer_zero_node, 0, 0);
  8907.           decls = TREE_CHAIN (decls);
  8908.         }
  8909.     }
  8910.       b = b->level_chain;
  8911.     }
  8912. }
  8913.